例如,会员注册的时候用户名,密码,姓名,年龄等
在用户名中输入完成以后,不点提交,自动检测用户名是否已被占用了这个例子有没有谁做过,哪位大哥提供个例子给我看看噻
在用户名中输入完成以后,不点提交,自动检测用户名是否已被占用了这个例子有没有谁做过,哪位大哥提供个例子给我看看噻
解决方案 »
- ASP.NET程序上传到服务器后不可以运行了
- ASP.NET防止别人刷票,求教解决办法
- select控件问题
- 初学ASP.NET,请问 无法找到脚本库"/aspnet_client/system_web/1_1_4322/webUIValidation.js".
- asp.net(C#)怎么实现弹出确认对话框问题?
- 再次提出来?????奇怪的问题datagrid嵌套datalist,datalist不能显示出来
- 大家看看我这样的下载代码有什么问题
- 关于treeview
- 请推荐一本介绍使用水晶报表的书
- 运用ViewState时出现无法返回结果异常!
- 如何读取FileUpload中的文件路径
- ----------------SQL Server中的sleeping越积越多,要我手工清除才行,怎么办呢?
http://www-128.ibm.com/developerworks/cn/xml/wa-ajaxintro1.html
做一下效果,等做出来了,我再仔细看看能给个例子不?
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
</httpHandlers>2.
private void Page_Load(object sender, System.EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(clsValdate) ,this);
}
3.
internal class clsValdate
{
[Ajax.AjaxMethod]
public string ValidateInput(string userName)
{
string su = "xxx";
//可以在这里操作.
string retVal = "用户不存在,可以使用!"; if(userName.Equals(su))
retVal = "用户名已存在,请选用其它用户名"; return retVal;
}
}4.
<script language="javascript" type="text/javascript">
function ValidateInputData()
{
var txt = document.all["txtUserName"];
if(txt.value == "")
{
Show("用户名不能为空");
return false;
}
var _value = clsValdate.ValidateInput(txt.value).value;
if(_value != null)
{
Show(_value);
}
return true;
}
function Show(message)
{
var objMessage = document.all["spMessage"];
objMessage.style.display = "";
objMessage.innerText = message;
}
</script>
5.
<table width="450" align="center" cellpadding="2">
<tr>
<td colspan="2" height="20px" align="center"><span id="spMessage" style="display:none;" class="ms"></span></td>
</tr>
<tr>
<td align="right">用户名</td>
<td>
<asp:TextBox id="txtUserName" onblur="return ValidateInputData();" runat="server" CssClass="tb"></asp:TextBox></td>
</tr>
<tr>
<td align="right">密码</td>
<td>
<asp:TextBox id="TextBox2" runat="server" CssClass="tb"></asp:TextBox></td>
</tr>
<tr>
<td align="right">确认密码</td>
<td>
<asp:TextBox id="TextBox3" runat="server" CssClass="tb"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button id="btnSubmit" runat="server" Text="Submit" CssClass="tb"></asp:Button></td>
</tr>
</table>
onfocus和onblur事件 ,没有什么,只是将单击事件换为光标事件
// .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxPro_CheckDuplicatedUserName.aspx.cs" Inherits="AjaxPro_AjaxPro_CheckDuplicatedUserName" %><!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>AjaxPro_CheckDuplicatedUserName</title>
<script type="text/javascript">
<!--function CheckDuplicatedUserName(sender)
{
var callback = function(res) {
var spnRes = document.getElementById("spnCheckDuplicatedUserNameResult");
var btnSubmit = document.getElementById("btnSubmit");
if(res.error) return alert(res.error.Message);
if(res.value) {
spnRes.innerHTML = "对不起,此用户名已被使用,请换用其他用户名。";
spnRes.style.backgroundColor = "f90";
sender.focus();
btnSubmit.disabled = true;
} else {
spnRes.innerHTML = "恭喜您,此用户名可以使用。";
spnRes.style.backgroundColor = "lightgreen";
btnSubmit.disabled = false;
}
}
AjaxProSample.CheckDuplicatedUserName(sender.value, callback);
}function btnSubmit_Click() {}// -->
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%">
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td width="100">
用户名:</td>
<td width="200">
<input id="txtUserName" type="text" onblur="CheckDuplicatedUserName(this)" /></td>
<td><span id="spnCheckDuplicatedUserNameResult" style="border: green 1px solid"></span>
</td>
</tr>
<tr>
<td>
密码:</td>
<td>
<input id="txtPassword" type="password" /></td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input id="btnSubmit" type="button" disabled="disabled" value="提交" onclick="return btnSubmit_Click()" /></td>
<td>
</td>
</tr>
</table>
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField HeaderText="已存在的用户名">
<ItemTemplate>
<%# Container.DataItem %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>// .aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
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 AjaxPro;[AjaxPro.AjaxNamespace("AjaxProSample")]
public partial class AjaxPro_AjaxPro_CheckDuplicatedUserName : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = GetSimulatingUserNameList();
GridView1.DataBind(); AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxPro_AjaxPro_CheckDuplicatedUserName));
} /// <summary>
/// 模拟的用户列表
/// </summary>
/// <returns></returns>
public static List<string> GetSimulatingUserNameList()
{
List<string> userNameList = HttpContext.Current.Session["SimulatingUserNameList"] as List<string>;
if (userNameList == null) {
userNameList = new List<string>();
userNameList.Add("Jack");
userNameList.Add("Tom");
userNameList.Add("Jim");
userNameList.Add("Leo");
userNameList.Sort(delegate(string x, string y) { return x.ToUpper().CompareTo(y.ToUpper()); });
HttpContext.Current.Session["SimulatingUserNameList"] = userNameList;
}
return userNameList;
} [AjaxMethod]
public static bool CheckDuplicatedUserName(string userName)
{
List<string> existedUserNames = GetSimulatingUserNameList();
// 不区分大小写
return (existedUserNames.BinarySearch(userName.ToUpper(), StringComparer.InvariantCultureIgnoreCase) > -1);
}
}
这个效果不错
<script type= "text/javascript " language= "javascript ">
var xmlHttp = null;
function CheckUser()
{
try
{
xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP ");
}
catch(err1)
{
try
{
xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP ");
}
catch(err2)
{
xmlHttp = new XMLHttpRequest();
}
}
var Text1 = document.getElementById( "Text1 ");
var url = "chkuser.aspx?User= " + Text1.value;
xmlHttp.open( "GET ",url,true);
xmlHttp.onreadystatechange = OnHandler;
xmlHttp.send(null); }
function OnHandler()
{
if(xmlHttp.readyState == 4)
{
var isValid = xmlHttp.responseText;
var exists = document.getElementById( "exsits ");
exists.innerHTML = isValid.substring(0,4);
}
}
</script>
<input id= "Text1 " type= "text " onblur= "CheckUser() " /> <label d= "exsits "> </label> <br /> 然后建一个chkuser.aspx,其后台代码改为
protected void Page_Load(object sender, EventArgs e)
{
string user = this.Request.QueryString[ "User "]; if (UserExist(user))
{
Response.Write( "存在 ");
}
else
{
Response.Write( "不存在 ");
} } private bool UserExist(string username)
{
ClassLib.Employee emp = new ClassLib.Employee();
return emp.EmpNameExist(username);
}
我用的也是AJAX PRO
http://blog.csdn.net/mndn_nana/archive/2008/01/10/2033764.aspx
LZ看过后便知晓