Asp.Net文本框失去焦点检查用户名是否存在
来源:互联网 发布:北京西班牙餐厅 知乎 编辑:程序博客网 时间:2024/06/07 07:08
DAL层
using System;
using System.Collections.Generic;
using System.Text;
using MODEL;
using System.Da
namespace DAL
{
public static class UserService
{
//检查用户名是否存在
public static bool CheckUserName(string username)
{
string sql = "select count(*) from My_UserMessage where uname = '" + username + "'";
try
{
int count = DBHelper.GetScalar(sql);
if (count > 0)
{
return false;
}
else
{
return true;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
}
}
BLL层
using System;
using System.Collections.Generic;
using System.Text;
using DAL;
namespace BLL
{
public static class UserManager
{
//检查用户是否存在
public static bool CheckUserName(string username)
{
return UserService.CheckUserName(username);
}
}
}
MODEL层
using System;
using System.Collections.Generic;
using System.Text;
namespace MODEL
{
public class UserMessage
{
private int id;
public int Id
{
get { return id; }
set { id = value; }
}
private string uname;
public string Uname
{
get { return uname; }
set { uname = value; }
}
private string password;
public string Password
{
get { return password; }
set { password = value; }
}
}
}
Web层
CheckUserName.aspx代码
(*注:文本框的AutoPostBack="true"的属性)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckUserName.aspx.cs" Inherits="CheckUserName" %>
<!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:TextBox ID="txtCheck" runat="server" On
<asp:Label ID="lblMessage" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" /></div>
</form>
</body>
</html>
CheckUserName.aspx.cs代码
using System;
using System.Da
using System.Configuration;
using System.Collections;
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 BLL;
using MODEL;
public partial class CheckUserName : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
//文本框改变事件
protected void txtCheck_TextChanged(object sender, EventArgs e)
{
bool result = UserManager.CheckUserName(txtCheck.Text.Trim());
if (result == true)
{
lblMessage.Text = "恭喜您,此用户名可以使用!";
Button1.Enabled = true;
}
if (result == false)
{
lblMessage.Text = "该用户名已存在,请更换用户名!";
Button1.Enabled = false;
}
}
}
- Asp.Net文本框失去焦点检查用户名是否存在
- 检查用户名是否存在
- asp.net验证用户名是否已经存在
- asp.net Jquery验证用户名是否存在
- asp.net ajax验证用户名是否存在
- asp.net验证用户名是否已经存在
- 检查用户名是否已存在
- AJAX异步检查,检查用户名是否存在
- asp.net无刷新验证用户名是否已经存在
- asp.net ajax+jquery 验证用户名是否存在
- asp.net AJAX 验证用户名是否存在 -Jquery
- asp.net AJAX 验证用户名是否存在 -Jquery
- asp.net AJAX 验证用户名是否存在 -Jquery
- asp.net AJAX 验证用户名是否存在 -Jquery
- asp.net AJAX 验证用户名是否存在 -Jquery
- asp.net AJAX 验证用户名是否存在 -Jquery
- asp.net AJAX 验证用户名是否存在 -Jquery
- asp.net AJAX 验证用户名是否存在 -Jquery
- 浅析Web工程目录和tomcat目录
- poj1752 - Advertisement
- c++重载的总结
- Asp.Net使用DataSet查询数据库数据
- struts2 ognl中几个标签方式用法
- Asp.Net文本框失去焦点检查用户名是否存在
- HDU 1018 Big Number数论(解题报告)
- Asp.Net数据库查询生成XML文件
- Asp.Net使用DataTable查询数据库数据
- python 在linux中使用sqlite3
- c语言中单引号和双引号的差别---解决从字符串中提取IP地址的困惑
- shader实现凹凸效果
- STM32F4xx FPU的设置(转)
- WinRAR提示“请购买WINRAR许可”的解决方法