5。示例代码:
aspx页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Namespace="cnblogs.suiqirui" TagPrefix="txt" %>
<!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>
<input type=hidden id=hi runat="server" />
用户名:
<txt:ajaxText runat=server ID=aj ClientCallBackScript=GetCallbackData EnableViewState=true OnTextChanged="aj_TextChanged" /><asp:label runat=server ID="Label1" ></asp:label><br />
密码: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text=" 注册" OnClick="Button1_Click" Width="216px" /></div>
<script>
function GetCallbackData(res)
{ if(res=="True")
{
document.getElementById("Label1").innerHTML="<font color=blue>成功</font>";
document.getElementById("hi").value="1";
}
else
{
document.getElementById("Label1").innerHTML="<font color=blue>该用户已存在</font>";
document.getElementById("hi").value="0";
}
}
</script>
</form>
</body>
</html>
cs页面:
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ViewState["valid"] = Request["hi"];
}
protected void aj_TextChanged(object sender, cn
blogs.suiqirui.TextChangedEventArgs e)
{
//模似用户aa
if (e.TextValue == "aa")
{
this.aj.IsValid = false;
}
else
{
this.aj.IsValid = true;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string s = (string)ViewState["valid"];
if (s == "0")
{
Response.Write(" 不能进行提交,因为未通过验证");
}
else {
Response.Write("可以正常注册了,我们就可以进行数据库操作了");
}
}
}
控件代码:见上
上述那个(4.0)
6.结语
终于完成了,休息一下了,呵呵,过两天,就出第三系列,如有不妥的地方,请大家更正。