欢迎光临
我们一直在努力

ASP.net中Panel控件用法-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

有朋友问起我panel控件有什么用,认为panel控件只不过是控制一些控件的整体输入输出,没有什么大的用途,呵呵,确实这样,panel控件的功能只能是这么点点,但是它一旦和其它的web控件结合起来使用,它的优点就显现出来了。

  我们下面来模拟一个用户申请的页面。申请分为四步,第一步输入用户名,第二步输入用户信息,第三步显示确定信息,第四步确认。如图1至图4

ASP.net中Panel控件用法-.NET教程,Asp.Net开发
图1

ASP.net中Panel控件用法-.NET教程,Asp.Net开发
图2

ASP.net中Panel控件用法-.NET教程,Asp.Net开发
图3

ASP.net中Panel控件用法-.NET教程,Asp.Net开发
图4

  在一般的技术中,我们每一步就需要一个程序用于判断显示,而在如果使用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 id=”panel0″ runat=”server” >
<table border=”1″ cellpadding=”0″ cellspacing=”0″ style=”border-collapse: collapse” bordercolor=”#111111″ width=”41%”>
<tr>
<td width=”100%” colspan=”3″ bgcolor=”#339966″ align=”center”>
<font color=”#ffff99″>第一步 选择用户名</font></td>
</tr>
<tr>
<td width=”33%” bgcolor=”#eeeddb”>用户名:</td>
<td width=”33%” bgcolor=”#eeeddb”>
<asp:textbox id=”username” runat=”server” /></td>
<td width=”34%” bgcolor=”#eeeddb”>
<asp:button id=”fristnextstep” text=”下一步” runat=”server” onclick=”nextstep”/></td>
</tr>
</table>
</asp:panel>

<asp:panel id=”panel1″ runat=”server”>
<table border=”1″ cellpadding=”0″ cellspacing=”0″ style=”border-collapse: collapse” bordercolor=”#111111″ width=”41%” height=”32″>
<tr>
<td width=”100%” colspan=”2″ bgcolor=”#339966″ align=”center” height=”15″>
<font color=”#ffff99″>第二步 填写用户信息</font></td>
</tr>
<tr>
<td width=”33%” bgcolor=”#eeeddb” height=”16″>用户名:</td>
<td width=”67%” bgcolor=”#eeeddb” height=”16″>
<%=username.text%> </td>
</tr>
<tr>
<td width=”33%” bgcolor=”#eeeddb” height=”16″>密码:</td>
<td width=”67%” bgcolor=”#eeeddb” height=”16″>
<asp:textbox textmode=”password” id=”passwd” runat=”server” /> </td>
</tr>
<tr>
<td width=”33%” bgcolor=”#eeeddb” height=”16″>确认密码:</td>
<td width=”67%” bgcolor=”#eeeddb” height=”16″>
<asp:textbox textmode=”password” id=”repasswd” runat=”server” /> </td>
</tr>
<tr>
<td width=”33%” bgcolor=”#eeeddb” height=”16″>地址:</td>
<td width=”67%” bgcolor=”#eeeddb” height=”16″>
<asp:textbox id=”address” runat=”server” /> </td>
</tr>
<tr>
<td width=”33%” bgcolor=”#eeeddb” height=”16″>邮政编码:</td>
<td width=”67%” bgcolor=”#eeeddb” height=”16″><asp:textbox id=”zipcode” runat=”server” /> </td>
</tr>
<tr>
<td width=”33%” bgcolor=”#eeeddb” height=”16″>简介:</td>
<td width=”67%” bgcolor=”#eeeddb” height=”16″>
<asp:textbox id=”comment” textmode=”multiline” wrap=”true” rows=”10″ runat=”server” /> </td>
</tr>
<tr>
<td width=”33%” bgcolor=”#eeeddb” height=”16″> </td>
<td width=”67%” bgcolor=”#eeeddb” height=”16″>
<asp:button id=”fristprevstep” text=”上一步” onclick=”prevstep” runat=”server”/>
  
<asp:button id=”secondnextstep” text=”下一步” onclick=”nextstep” runat=”server” /> </td>
</tr>
</table>
</asp:panel>

<asp:panel id=”panel2″ runat=”server”>
<table border=”1″ cellpadding=”0″ cellspacing=”0″ style=”border-collapse: collapse” bordercolor=”#111111″ width=”41%” height=”32″>
<tr>
<td width=”100%” colspan=”2″ bgcolor=”#339966″ align=”center” height=”15″>
<font color=”#ffff99″>第三步 确认用户信息</font></td>
</tr>
<tr>
<td width=”33%” bgcolor=”#eeeddb” height=”16″>用户名:</td>
<td width=”67%” bgcolor=”#eeeddb” height=”16″>
<asp:label id=”fusername” runat=”server” /> </td>
</tr>
<tr>
<td width=”33%” bgcolor=”#eeeddb” height=”16″>密码:</td>
<td width=”67%” bgcolor=”#eeeddb” height=”16″>
<asp:label id=”fpasswd” runat=”server” /> </td>
</tr>
<tr>
<td width=”33%” bgcolor=”#eeeddb” height=”16″>地址:</td>
<td width=”67%” bgcolor=”#eeeddb” height=”16″>
<asp:label id=”faddress” runat=”server” /> </td>
</tr>
<tr>
<td width=”33%” bgcolor=”#eeeddb” height=”16″>邮政编码:</td>
<td width=”67%” bgcolor=”#eeeddb” height=”16″>
<asp:label id=”fzipcode” runat=”server” /> </td>
</tr>
<tr>
<td width=”33%” bgcolor=”#eeeddb” height=”16″>简介:</td>
<td width=”67%” bgcolor=”#eeeddb” height=”16″>
<asp:label id=”fcomment” runat=”server” /> </td>
</tr>
<tr>
<td width=”33%” bgcolor=”#eeeddb” height=”16″> </td>
<td width=”67%” bgcolor=”#eeeddb” height=”16″>
<asp:button id=”secondprevstep” text=”上一步” onclick=”prevstep” runat=”server” />
  
<asp:button id=”finishstep” text=”完成” onclick=”nextstep” runat=”server” /> </td>
</tr>
</table>
</asp:panel>
<asp:panel id=”panel3″ runat=”server”>
<table border=”1″ cellpadding=”0″ cellspacing=”0″ style=”border-collapse: collapse” bordercolor=”#111111″ width=”41%”>
<tr>
<td width=”100%” colspan=”3″ bgcolor=”#339966″ align=”center”>
<font color=”#ffff99″>恭喜您,您已经完成了所有的操作</font>
</td>
</tr>
<tr>
<td colspan=”3″ bgcolor=”#eeeddb”>请您…….</td>
</tr>
</table>
</asp:panel>

</form>
</body>
</html>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP.net中Panel控件用法-.NET教程,Asp.Net开发
分享到: 更多 (0)

相关推荐

  • 暂无文章