在asp.net中有兩種容器控件,其中包括panel和placeholder控件。
使用panel控件可以對控件進行分組。一幫助組織web窗體也的内容,将控件組織在面闆中,可提供有關在運作時控件應如何分頁顯示的資訊。這裡也就是我們所說的在一個頁面中通過“送出”或“下一步”按鈕來顯示不同的虛假頁面,即通過隐藏可以實作,還有panel的外觀屬性,來設定panel的外觀特性。
簡單的使用者注冊流程圖:
html代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="容器控件._Default"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>使用者注冊流程圖</title>
<style type="text/css">
.style1
{
text-align: center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" BorderStyle="Groove" Height="333px"
style="text-align: center" Width="909px"><h1>使用者注冊</h1>
<table style="height: 218px">
<tr id="Tr1" runat="server">
<td>使用者名:</td>
<td><asp:TextBox runat="server" ID="username"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="username" Display="Dynamic" ErrorMessage="請正确輸入使用者名"></asp:RequiredFieldValidator><! 對使用者輸入的資訊進行非空驗證,并為動态顯示,如驗證不通過彈出”請輸入使用者名“>
</td>
</tr>
<tr>
<td>密碼:</td>
<td><asp:TextBox runat="server" ID="password1" TextMode="Password"></asp:TextBox> </td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="password1" Display="Dynamic" ErrorMessage="請輸入密碼!"></asp:RequiredFieldValidator><! 對密碼進行非空驗證,并為動态顯示,錯誤時提示:請輸入密碼>
</td>
<td>密碼确認:</td>
<td><asp:TextBox runat="server" ID="password2" TextMode="Password"></asp:TextBox></td>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="password1" ControlToValidate="password2" Display="Dynamic"
ErrorMessage="請确認密碼正确性"></asp:CompareValidator><!這裡的controltocompare是對第一次輸入的密碼進行比較,測試十分保持一緻>
<td>性别:</td>
<asp:RadioButton Text="男" ID="rd1" runat="server" GroupName="1" /><!groupname必須相同>
<asp:RadioButton Text="女" ID="rd2" runat="server" GroupName="1" />
</td>
<td></td>
<td>聯系電話:</td>
<td><asp:TextBox runat="server" ID="telephone"></asp:TextBox></td><!正規表達式偶還沒學>
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="請輸入電話号碼"
MaximumValue="199999999999" MinimumValue="0"
ControlToValidate="telephone"></asp:RangeValidator><!比較粗糙的定義範圍,最小值為0.,最大值為19999999999>
</td>
<td>興趣愛好:</td>
<asp:CheckBox runat="server" ID="cb1" Text="籃球" />
<asp:CheckBox runat="server" ID="cb2" Text="足球" />
<asp:CheckBox runat="server" ID="cb3" Text="排球" />
<asp:CheckBox runat="server" ID="cb4" Text="讀書" />
<td colspan="2" style="text-align: center">
</td>
</table>
<asp:Button ID="Button1" runat="server" Text="下一步" onclick="Button1_Click" />
<br />
</asp:Panel>
</div><br/>
<asp:Panel ID="Panel2" runat="server" BorderStyle="Groove" Height="270px"
Visible="False"><h3 style="text-align: center">确認資訊</h3>
<p style="text-align: center">
使用者名:<asp:Label ID="xusername" runat="server" Text="Label" Width="161px"></asp:Label>
</p>
密碼:<asp:Label ID="xpassword" runat="server" Text="Label" Width="161px"></asp:Label>
聯系電話:<asp:Label ID="xtelephone" runat="server" Text="Label" Width="161px"></asp:Label>
興趣愛好:<asp:Label ID="xaihao" runat="server" Text="Label" Width="161px"></asp:Label>
<asp:Button ID="Button2" runat="server" Text="下一步" onclick="Button2_Click" />
</asp:Panel>
<asp:Panel ID="Panel3" runat="server" Height="411px" Width="920px">
<h1 class="style1">恭喜您注冊成功</h1>
<p class="style1">
請切記您賬号和密碼:</p>
<p style="text-align: center">
使用者名:<asp:Label ID="Label1" runat="server" Text="Label" Width="161px"></asp:Label>
密碼:<asp:Label ID="Label2" runat="server" Text="Label" Width="161px"></asp:Label>
</p>
</form>
</body>
</html>
背景c#代碼:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace 容器控件
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
this.Panel3.Visible = false;//放在這裡實在頁面加載時就把panel3隐藏
protected void Button1_Click(object sender, EventArgs e)
this.Panel1.Visible = false;//點選按鈕“下一步”是panel1隐藏
this.Panel2.Visible = true;//同時panel2顯示出來
this.xusername.Text = this.username.Text;//把使用者的資訊放到自定義的label中,感覺很麻煩,希望會有更好的辦法
this.xpassword.Text = this.password1.Text;
this.xtelephone.Text = this.telephone.Text;
protected void Button2_Click(object sender, EventArgs e)
this.Panel2.Visible = false;//點選按鈕“下一步”是panel2隐藏
this.Panel3.Visible = true;//同時panel3顯示出來
}
}
整個流程圖比較簡單,運用的主要是textbox控件,label控件,驗證控件,Button控件,panel容器控件,其中驗證空間運用的比較粗糙,繼續改進。
本文轉自shenzhoulong 51CTO部落格,原文連結:http://blog.51cto.com/shenzhoulong/296058,如需轉載請自行聯系原作者