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>
学会举一反三!
 

你可能感兴趣的:(c,asp,注册,登陆,窗体)