ASP.net中Panel控件用法
点击次数:19 次 发布日期:2008-11-26 16:15:59 作者:源代码网
|
源代码网推荐 源代码网推荐 我们下面来模拟一个用户申请的页面。申请分为四步,第一步输入用户名,第二步输入用户信息,第三步显示确定信息,第四步确认。如图1至图4 源代码网推荐 源代码网推荐
源代码网推荐 源代码网推荐 图1 源代码网推荐 源代码网推荐 源代码网推荐
源代码网推荐 源代码网推荐 图2 源代码网推荐 源代码网推荐 源代码网推荐
源代码网推荐 源代码网推荐 图3 源代码网推荐 源代码网推荐
源代码网推荐 源代码网推荐 源代码网推荐 图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> 源代码网推荐&nb;<td sp;<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"> 源代码网推荐 &able b紅able 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" erver""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> 做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。 源代码网推荐 源代码网供稿. |
