c# asp.net 簡單窗體註冊登錄(3)

通常性博客及遊戲等用戶的註冊都會用到簡單的登錄或者註冊窗體:
web 務器控件部分要注意的是對用戶輸入數據的審查即對用戶輸入信息的登錄驗證,還有就是對textbox控件的模式選擇,選擇textmode爲password,以及對各控件的非空斷定,有時候還須要用到正則表達式進行限制,對於單選按鈕radio其group那麼要設置在同一組內,以便選擇是隻能選擇一個; 每個web控件 必須是runat=「sever」!!!!
其主要代碼以下:

<body>
        <form id= "form1" runat= "server">
<table>
<tr 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>
<td>
        <asp:RequiredFieldValidator ID= "RequiredFieldValidator2" runat= "server"
                ControlToValidate= "password1" Display= "Dynamic" ErrorMessage= "請輸入密碼!"></asp:RequiredFieldValidator><!對密碼進行非空驗證,併爲動態顯示,錯誤時提示:請輸入密碼>
                        </td>
</tr>
<tr>
<td>密碼確認:</td>
<td><asp:TextBox runat= "server" ID= "password2" TextMode= "Password"></asp:TextBox></td>
<td>
        <asp:CompareValidator ID= "CompareValidator1" runat= "server"
                ControlToCompare= "password1" ControlToValidate= "password2" Display= "Dynamic"
                ErrorMessage= "請確認密碼正確性"></asp:CompareValidator><!這裏的controltocompare是對第一次輸入的密碼進行比較,測試十分保持一致>
                        </td>
</tr>
<tr>
<td>性別:</td>
<td>
<asp:RadioButton Text= "男" ID= "rd1" runat= "server" GroupName= "1" /><!groupname必須相同>
<asp:RadioButton Text= "女" ID= "rd2" runat= "server" GroupName= "1" />
</td>
<td></td>
</tr>
<tr>
<td>聯繫電話:</td>
<td><asp:TextBox runat= "server" ID= "telephone"></asp:TextBox></td><!正則表達式偶還沒學>
<td></td>
</tr>
<tr>
<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>
<td></td>
</tr>
<tr>
<td colspan= "2" style= "text-align: center">
        <asp:Button ID= "bt" runat= "server"
                Text= "提交" onclick= "bt_Click" />
        </td>
<td></td>
</tr>
</table>
        
</form>
        
</body>
學會觸類旁通!  
相關文章
相關標籤/搜索