<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken

 

 

<!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>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<asp:ScriptManager ID="ScriptManager1" runat="server">
        
</asp:ScriptManager>
    
    
</div>
        
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            
<ContentTemplate>
                
<asp:TextBox ID="tb_username" runat="server" Width="85px" AutoPostBack="True"

>


 

 System.Data.SqlClient;

 

 

public partial class Index : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    {
        
if (!this.IsPostBack)
        {
            ScriptManager1.SetFocus(
"tb_username");
        }
    }
    
private bool CheckUser()
    {
        
int count = 0;
        SqlConnection conn 
= new SqlConnection("server=.;uid=sa;pwd='';database=UserInfo");
        
string username = this.tb_username.Text;
        
string strsql = "select count(uid) from userinfo where username='"+username+"'";
        SqlCommand cmd 
= new SqlCommand(strsql,conn);
        conn.Open();
        count 
= (int)cmd.ExecuteScalar();
        conn.Close();
        
if (count == 0)
        {
            
return true;
        }
        
else
        {
            
return false;
        }

 

    }

 

protected void Button1_Click(object sender, EventArgs e)
    {
        
if (!CheckUser())
        {
            
this.lb_info.Text = "用户名已经存在";
            ScriptManager.RegisterStartupScript(
this.UpdatePanel1, UpdatePanel1.GetType(), "",

);
        }


 

摘自http://www.cnblogs.com/lavenderzh/archive/2009/05/23/1487588.html

相关文章:

  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2021-10-15
  • 2021-06-21
猜你喜欢
  • 2021-11-17
  • 2021-05-23
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案