ASP.net中Panel控件用法
在一般的技术中,我们每一步就需要一个程序用于判断显示,而在如果使用Panel控件,这四步(或者是更多的步骤)都可以合为一个页面搞定。按照朋友的意思,我把源程序帖出来,下面是程序,由于最近我们的时间较紧,飞刀就不多解释了,请大家自已理解了。主要是利用Web控件的保值特性:
<Script Language="C#" Runat="Server">
public void Page_Load(Object src,EventArgs e)
{
if(!Page.IsPostBack)
{
file://初始化Panel
State["PanelSeed"] = 0;
Panel0.Visible = true;
Panel1.Visible = false;
Panel2.Visible = false;
Panel3.Visible = false;
}
}
public void PrevStep(Object src,EventArgs e)
{
file://大家没有忘记State吧。
string CurrentPanel = "Panel"+State["PanelSeed"].ToString();
State["PanelSeed"] = (int)State["PanelSeed"]-1;
string PrevPanel = "Panel"+State["PanelSeed"].ToString();
file://这里注意FindControl的用法
Panel p = (Panel)FindControl(CurrentPanel);
p.Visible = false;
p = (Panel)FindControl(PrevPanel);
p.Visible = true;
}
public void NextStep(Object src,EventArgs e)
{
string CurrentPanel = "Panel"+State["PanelSeed"].ToString();
State["PanelSeed"] = (int)State["PanelSeed"]+1;
string NextPanel = "Panel"+State["PanelSeed"].ToString();
Panel p = (Panel)FindControl(CurrentPanel);
p.Visible = false;
p = (Panel)FindControl(NextPanel);
p.Visible = true;
if((int)State["PanelSeed"]==2)
{
FUserName.Text = UserName.Text;
FPasswd.Text = Passwd.Text;
FAddress.Text = Address.Text;
FZipCode.Text = ZipCode.Text;
FComment.Text = Comment.Text;
}
}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form runat="server">
<asp:Panel runat="server" >
<table cellpadding="0" cellspacing="0" bordercolor="#111111">
<tr>
<td colspan="3" bgcolor="#339966">
<font color="#FFFF99">第一步 选择用户名</font></td>
</tr>
<tr>
<td bgcolor="#EEEDDB">用户名:</td>
<td bgcolor="#EEEDDB">
<asp:TextBox runat="Server" /></td>
<td bgcolor="#EEEDDB">
<asp:Button Text="下一步" runat="server"/></td>
</tr>
</table>
</asp:Panel>
<asp:Panel runat="server">
<table cellpadding="0" cellspacing="0" bordercolor="#111111">
<tr>
<td colspan="2" bgcolor="#339966">
<font color="#FFFF99">第二步 填写用户信息</font></td>
</tr>
<tr>
<td bgcolor="#EEEDDB">用户名:</td>
<td bgcolor="#EEEDDB">
<%=UserName.Text%> </td>
</tr>
<tr>
<td bgcolor="#EEEDDB">密码:</td>
<td bgcolor="#EEEDDB">
<asp:TextBox TextMode="Password" runat="server" /> </td>
</tr>
<tr>
<td bgcolor="#EEEDDB">确认密码:</td>
<td bgcolor="#EEEDDB">
<asp:TextBox TextMode="Password" runat="server" /> </td>
</tr>
<tr>
<td bgcolor="#EEEDDB">地址:</td>
<td bgcolor="#EEEDDB">
<asp:TextBox runat="server" /> </td>
</tr>
<tr>
<td bgcolor="#EEEDDB">邮政编码:</td>
<td bgcolor="#EEEDDB"><asp:TextBox runat="server" /> </td>
</tr>
<tr>
<td bgcolor="#EEEDDB">简介:</td>
<td bgcolor="#EEEDDB">
<asp:TextBox TextMode="MultiLine" Wrap="True" Rows="10" runat="Server" /> </td>
</tr>
<tr>
<td bgcolor="#EEEDDB"> </td>
<td bgcolor="#EEEDDB">
<asp:Button Text="上一步" runat="server"/>
<asp:Button Text="下一步" runat="server" /> </td>
</tr>
</table>
</asp:Panel>
<asp:Panel runat="server">
<table cellpadding="0" cellspacing="0" bordercolor="#111111">
<tr>
<td colspan="2" bgcolor="#339966">
<font color="#FFFF99">第三步 确认用户信息</font></td>
</tr>
<tr>
<td bgcolor="#EEEDDB">用户名:</td>
<td bgcolor="#EEEDDB">
<asp:Label runat="Server" /> </td>
</tr>
<tr>
<td bgcolor="#EEEDDB">密码:</td>
<td bgcolor="#EEEDDB">
<asp:Label runat="Server" /> </td>
</tr>
<tr>
<td bgcolor="#EEEDDB">地址:</td>
<td bgcolor="#EEEDDB">
<asp:Label runat="Server" /> </td>
</tr>
<tr>
<td bgcolor="#EEEDDB">邮政编码:</td>
<td bgcolor="#EEEDDB">
<asp:Label runat="Server" /> </td>
</tr>
<tr>
<td bgcolor="#EEEDDB">简介:</td>
<td bgcolor="#EEEDDB">
<asp:Label runat="Server" /> </td>
</tr>
<tr>
<td bgcolor="#EEEDDB"> </td>
<td bgcolor="#EEEDDB">
<asp:Button Text="上一步" runat="server" />
<asp:Button Text="完成" runat="server" /> </td>
</tr>
</table>
</asp:Panel>
<asp:Panel runat="server">
<table cellpadding="0" cellspacing="0" bordercolor="#111111">
<tr>
<td colspan="3" bgcolor="#339966">
<font color="#FFFF99">恭喜您,您已经完成了所有的操作</font>
</td>
</tr>
<tr>
<td colspan="3" bgcolor="#EEEDDB">请您.......</td>
</tr>
</table>
</asp:Panel>
</form>
</body>
</html>
共2页。
共2页。