Panel Web 控件可以让我们群组控件,让我们决定在Panel 中的控件是否要显示出来。其使用语法为:
<ASP:Panel
Id="被程序代码所控制的名称"
Runat="Server"
BackImageUrl="URL"
HorziontalAlign="Center | Justify | Left | NotSet | Right"
Wrap="True | False"
>
其它控件...
</ASP:Panel>
Panel Web 控件的基本属性如下所示:
下面范例为计算男女标准体重:
<Html>
<Form Id="Form1" Runat="Server">
<ASP:Panel Id="Main" Runat="Server"> <!--配置主Panel-->
标准体重计算程序<Hr>
依您的性别进入不同的计算方法
<ASP:Button Id="btnMan" Text="我是男生" OnClick="btnMan_Click"
Runat="Server"/>
<ASP:Button Id="btnWoman" Text="我是女生" OnClick="btnWoman_Click"
Runat="Server" />
</ASP:Panel>
<ASP:Panel Id="Man" Runat="Server"> <!--配置计算男生体重的Panel-->
输入您的身高:<ASP:TextBox Id="txtMan" Runat="Server" />
<ASP:Button Id="ShowResult1" Text="看结果" OnClick="ShowMan"
Runat="Server" />
</ASP:Panel>
<ASP:Panel Id="Woman" Runat="Server"> <!--配置计算女生体重的Panel-->
输入您的身高:<ASP:TextBox Id="txtWoman" Runat="Server" />
<ASP:Button Id="ShowResult2" Text="看结果" OnClick="ShowWoman"
Runat="Server" />
</ASP:Panel>
<ASP:Panel Id="Result" Runat="Server"> <!--配置显示标准体重的Panel-->
您的标准体重为:<ASP:Label Id="lblBody" Runat="Server" />公斤
</ASP:Panel>
</Form>
<Script Language="VB" Runat="Server">
Sub Page_Load(Sender As Object,e As Eventargs)
If Not Page.IsPostBack Then '第一次执行时只显示主Panel
Man.Visible=False
Woman.Visible=False
Result.Visible=False
End If
End Sub
Sub btnMan_Click(Sender As Object,e As Eventargs)
Main.Visible=False '将主Panel 隐藏, 计算男生体重的Panel 显示
Man.Visible=True
End Sub
Sub btnWoman_Click(Sender As Object,e As Eventargs)
Main.Visible=False '将主Panel 隐藏, 计算女生体重的Panel 显示
Woman.Visible=True
End Sub
Sub ShowMan(Sender As Object,e As Eventargs)
Man.Visible=False '将计算男生体重的Panel 隐藏, 显示计算结果
Result.Visible=True
lblBody.Text=Cint((Cint(txtMan.Text)-80)*0.7)
End Sub
Sub ShowWoman(Sender As Object,e As Eventargs)
Woman.Visible=False '将计算女生体重的Panel 隐藏, 显示计算结果
Result.Visible=True
lblBody.Text=Cint((Cint(txtWoman.Text)-70)*0.6)
End Sub
</Script>
</Html>