- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.SqlClient;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
- {
- string userName = args.Value;
- SqlConnection con = new SqlConnection("server=.;database=login;uid=sa;pwd=;");
- con.Open();
- SqlCommand cmd = new SqlCommand();
- cmd.CommandText = "select count(*) from login where userName='"+userName+"'";
- cmd.Connection = con;
- int count = Convert.ToInt32(cmd.ExecuteScalar());
- if (count > 0) args.IsValid = false;
- else args.IsValid = true;
- con.Close();
- }
- }
ASP.NET学习笔记--自定义验证控件的使用
最新推荐文章于 2013-11-23 09:33:00 发布