Normally the Panel control is used as a container and
works as a wrapper for other html or asp.net controls. This control is often used to generate
controls dynamically and add it to the asp:Panel. It can also be used to
display and hide group of controls.
To read hundreds of .NET
How to's like this, click
In this example, we will use an asp:Panel control and some
text to display as an output. This is actually not very large, but it should
serve the purpose of showing what can be done with the asp:Panel.
So to use this approach, add below code in your ASPX
This content is inside the Panel control.
protected void Page_Load(object sender, EventArgs e)
Label lbl = new Label();
lbl.Text = "This is the text of Literal control";
lbl.ID = "litLiteral";
This is added programmatically"));
In the above code, we have an asp:Panel control in
which we are adding a static text as well as dynamically generated asp:Label
control. To control its output, we can set Visible
property to true or false based on our need (Visible property is available for
all asp.net server control or html server control).
Now when we run the page with above code snippets, its
output should appear something like below image.
Here the 1st text is static text written on
the .aspx page. The 2nd text is written by adding the asp:Label
control from the server side and the third text is also written by adding the LiteralControl
from the server side.
I hope you can see how easy it is to utilize asp:Panel
controls in order to dynamically add/remove controls or hide/display controls