设为首页
收藏本站
最近更新

文章搜索
本类热门

 

首页 >> 网络编程 >> ASP.NET >> ASP.NET技巧 >> 新闻正文 [字体:  ] [打印文档
ASP.net中Panel控件用法

文章作者:飞刀
责任编辑:大鱼 录入时间:2005-1-24 14:21:43 来源:aspcn
频道声明:本频道的文章除部分特别声明禁止转载的专稿外,可以自由转载.但请务必注明出出处和原始作者 文章版权归本频道与文章作者所有.对于被频道转载文章的个人和网站,我们表示深深的谢意. 

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

  我们下面来模拟一个用户申请的页面。申请分为四步,第一步输入用户名,第二步输入用户信息,第三步显示确定信息,第四步确认。如图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>
<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>
推荐好友 | 频道收藏 | 打印文档 | 报告错误  
相关连接
·ASP.net中Panel控件用法
·DataGrid鼠标事件处理
·ASP.NET页面间的传值的几种方法
·使用ASP.NET中的一点体会--关于代码分离
·Asp.net页面输出到EXCEL
·不该错的问题:IsPostBack in ASP.NET, Programming with DataGrid
·asp.net中读取数据库的两种方式
·ASP Forum2.0学习笔记之二---了解Master Pages库
同一专题
·无相关专题
发表评论 版权声明:除部分特别声明不要转载,或者授权我站独家播发的文章外,大家可以自由转载我站点的原创文章,但原作者和来自我站的链接必须保留(非我站原创的,按照原来自一节,自行链接)。文章版权归我站和作者共有
转载
要求转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印,亦不能抹去我站点水印。
共有评论查看评论
姓名: