Web Server Controls->ASP.NET Panel Control

Definition and Usage

The Panel control is used as a container for other controls.

Tip: This control is often used to generate controls by code and to display and hide groups of controls.

Note: This control renders as an HTML <div> element in IE and as a <table> tag in Mozilla.


Properties

Property Description
BackImageUrl Specifies a URL to an image file to display as a background for this control
HorizontalAlign Specifies the horizontal alignment of the content. Legal values are:
  • Center
  • Justify
  • Left
  • NotSet
  • Right
id A unique id for the control
runat Specifies that the control is a server control.  Must be set to "server"
Wrap A Boolean value that specifies whether the content should wrap or not

Examples

Panel
ASPX Source:

<script  runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
   if check1.Checked then
     panel1.Visible=false
   else
     panel1.Visible=true
   end if
End Sub
</script>

<html>
<body>

<form runat="server">
<asp:Panel id="panel1"
runat="server" BackColor="#ff0000"
Height="100px" Width="100px">
Hello World!
</asp:Panel>
<asp:CheckBox id="check1"
Text="Hide Panel control"
runat="server"/>
<br /><br />
<asp:Button Text="Reload" runat="server" />
</form>

</body>
</html>

Output Result:
Hello World!


  

 If you click the panel contro "Hide Panel control" and then click the button "Reload", it will show:


  

 If you unclick the panel contro "Hide Panel control" and then click the button "Reload", it will show:
Hello World!


  

In this example we declare one Panel control, one CheckBox control, and one Button control in an .aspx file. When the user checks the CheckBox control, and the clicks the Refresh button, the Panel control will hide.

posted on 2007-03-27 09:47  改变热爱  阅读(280)  评论(0)    收藏  举报

导航