Subscribe

RSS Feed (xml)

Selectively Hiding or Revealing Portions of a Web Form Programmatically in ASP.NET

Toggle the Visible property of controls that inherit from System.Web.UI.Control.The
ASPX page:
<html>
<body>
<form runat=”server”>
<asp:panel id=”pnlSample” runat=”server”>
<asp:Label id=”lblSample” runat=”server” Text=”Sample Text” />
</asp:panel>
<asp:button runat=”server” id=”btnToggle” Text=”Toggle Panel Visibility”
OnClick=”btnToggle_Click” />
</form>
</body>
</html>
In <script runat=”server” /> block or codebehind:
Sub btnToggle_Click(sender as object, e as EventArgs)
pnlSample.Visible = Not pnlSample.Visible
End Sub

The Panel control used here can contain other controls.When setting the Visible property
of the Panel, the change is reflected through the controls within the panel as well.
Because all the Web Server Controls inherit from System.Web.UI.Control, you can utilize
the Visible property of each of them.This property can be set to True or False.

No comments:

Variety in the Web World