服务器控件和客户端控件的交替使用,主要还是获取到各个控件的值,直接用C#或Js判断是否符合条件就可以。

这里是以服务器控件为例子,至于客户端控件则需要写JS代码

、UserBF
public class UserBF
{
private MyDBDataContext _context;
public UserBF()
{
_context = new MyDBDataContext();
}
public bool Select(string UserName,string UserPwd) //验证用户名
{
var query = _context.LoginUser.Where(P=>P.UserName==UserName&&P.UserPwd==UserPwd);
return query.Count() > ;
}
public bool Login(string UserID)//验证ID是否唯一
{
var query = _context.LoginUser.Where(P => P.UserID==UserID);
return query.Count() > ;
}
public void Insert(string userid,string username,string userpwd)
{
LoginUser data = new LoginUser();
data.UserID = userid;
data.UserName = username;
data.UserPwd = userpwd;
_context.LoginUser.InsertOnSubmit(data);
_context.SubmitChanges();
}
}
、前台设计
<form id="form1" runat="server" >
<div>
<center><h1>注册页面</h1></center> <div>
<center>
<h1>服务器控件</h1>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label ID="Label5" runat="server" Text="用户ID:"></asp:Label>&nbsp;<asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged"></asp:TextBox><input id="Button3" type="button" value="唯一验证" runat="server" onserverclick="Button3_ServerClick" ><br>
<asp:Label ID="Label6" runat="server" Text="用户名:"></asp:Label>&nbsp;<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br>
<asp:Label ID="Label7" runat="server" Text="密码:"></asp:Label>&nbsp;&nbsp;&nbsp;<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br>
<asp:Label ID="Label8" runat="server" Text="确认密码:"></asp:Label><asp:TextBox ID="TextBox5" runat="server"></asp:TextBox><br>
<asp:Button ID="Button4" runat="server" Text="注册" Enabled="False" OnClick="Button1_Click" />
</center>
</div>
</from>
、在C#后台写验证的代码
protected void Button1_Click(object sender, EventArgs e)//服务器的注册
{
string userid = TextBox2.Text;
string username = TextBox3.Text;
string userpwd = TextBox4.Text;
string userpwdagain = TextBox5.Text;
if(userid=="")
{
Response.Write("<script>alert('用户ID不能为空!!')</script>");
}
else if(username=="")
{
Response.Write("<script>alert('用户名不能为空!!')</script>");
}
else if (userpwd == "")
{
Response.Write("<script>alert('用户密码不能为空!!')</script>");
}
else if (userpwd != userpwdagain)
{
Response.Write("<script>alert('两次密码不一样,请重新输入!!')</script>");
}
else
{
new UserBF().Insert(userid,username,userpwd);
Response.Write("<script>alert('注册成功!!')</script>"); }
}
protected void Button3_ServerClick(object sender, EventArgs e)//服务器唯一验证
{
if (string.IsNullOrWhiteSpace(TextBox2.Text))
{
Response.Write("<script>alert('用户ID不能为空!!')</script>"); }
else
{
bool isok = new UserBF().Login(TextBox2.Text);
if (isok)
{
Response.Write("<script>alert('此ID已存在,请更改!!')</script>");
}
else
{
Response.Write("<script>alert('恭喜你可以使用!!!')</script>");
Button4.Enabled = true;
}
}
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
Button4.Enabled = false;
}

效果图:

→→

Webform——注册验证的更多相关文章

  1. MVC中使用WebMail 发送注册验证信息

    在MVC中发送Email 可以使用WebMail :使用起来十分简单.如下: WebMail.SmtpServer = ConfigurationHelper.GetValue("SmtpS ...

  2. Ajax注册验证用户名是否存在 ——引自百度经验

    Ajax注册验证用户名是否存在 http://jingyan.baidu.com/article/a948d6515fdf870a2dcd2e85.html

  3. PHP+Ajax 异步通讯注册验证

    HTML代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...

  4. jQuery失去焦点的时候注册验证

    //注册验证$('form :input').blur(function () { if ($("#txtName").val() == "") { $(&qu ...

  5. SpringBoot注册登录(三):注册--验证账号密码是否符合格式及后台完成注册功能

    SpringBoot注册登录(一):User表的设计点击打开链接SpringBoot注册登录(二):注册---验证码kaptcha的实现点击打开链接      SpringBoot注册登录(三):注册 ...

  6. thinkphp+jquery+ajax前后端交互注册验证

    thinkphp+jquery+ajax前后端交互注册验证,界面如下 register.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1. ...

  7. Python学习:8.小项目之登录注册验证

    简介 本次项目登录注册验证是对之前学习知识点的加深学习,这次项目的练习的知识点有函数.判断语句.循环语句.文件操作等. 项目流程 运行代码之后,输出登录或者注册选项. 当选择登录之后,输入用户名密码, ...

  8. Java实现发送邮箱验证码/注册验证链接

    本文以163邮箱为例 1.准备(邮箱账号,邮箱必须设置POP3/SMTP/IMAP,设置步骤如下:) >>步骤:1 开启授权码服务 >>步骤:2 手机获取验证码 >> ...

  9. jquery注册验证的写法

    在做注册页面时会用到jquery验证注册信息,用户名,密码,邮箱,手机号的验证,比较简单的,新手莫怪... <script> function Name(){ var name = $(& ...

随机推荐

  1. [PR & ML 3] [Introduction] Probability Theory

    虽然学过Machine Learning和Probability今天看着一part的时候还是感觉挺有趣,听惊呆的,尤其是Bayesian Approach.奇怪发中文的笔记就很多人看,英文就没有了,其 ...

  2. windows phone 操作 http异步返回结果

    wp中为了提升用户体验,砍掉了http的同步操作,仅支持http异步请求,那么该如何及时处理异步操作返回的结果.纠结了很久,终于在技术群中好友的帮助下解决了问题,借助事件,将异步编程模型模式简单的处理 ...

  3. 51nod贪心算法入门-----任务分配问题

    任务执行顺序 有N个任务需要执行,第i个任务计算时占R[i]个空间,而后会释放一部分,最后储存计算结果需要占据O[i]个空间(O[i] < R[i]). 分析: 可以抽象成,从一个整数开始,每次 ...

  4. POJ2255二叉树

    题目大意就是给出你一个二叉树的前序和中序,要你求后序. 思路:二叉树的排序就是根据根节点的位置来定义的.所以找到二叉树的根节点是最重要的,二叉树的左子树和右子树也可以看成是二叉树,以此递归: #inc ...

  5. thinkphp验证码的实现

    两种验证码验证实现,一种直接在form表单提交按钮实现验证,一种使用ajax传递参数实现验证: 1.直接在form表单提交按钮实现验证,在控制器VerifyController.class.php中写 ...

  6. LAMP虚拟主机配置以及控制目录访问

    3.基于域名的虚拟主机配置 NameVirtualHost192.168.3.32:80#apache2.2.xx版本需要开启此选项,而且要和下面的保持一致:2.4.x版本就不需要此项设置了 < ...

  7. SDC(3)–set_multicycle_path 最关键的一张图

    上图意思是,假如使用 –setup option,默认约束的是 latch clock:假如使用 –hold option,默认约束的是 launch clock.箭头表示不同组合下时钟沿的移动方向. ...

  8. entity framework in mysql

    To start using Entity Framework 6 and Visual Studio 2013 is necessary to install MySQL for Visual St ...

  9. ExtJS4中initComponent和constructor的区别

    Ext的define方法参数类型define( String className, Object data, Function createdFn ) 创建自定义类时,先构造(constructor) ...

  10. Dynamic Programming (DP) 问题总结

    所有的 DP 问题都可以简单得用 Recursion 的方式实现.这通常是最容易想到的思路. 问题是这种实现不够 efficient,存在 subproblem 被重复计算的情况.有两种解决这个问题的 ...