AJAX判断用户名是否被注册
用的标签有ScriptManager,UpdatePanel,UpdateProgress ,主要的是UpdatePanel中的Triggers属性一定要对。
前台代码
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtName" runat="server" OnTextChanged="txtName_TextChanged" AutoPostBack="true" ></asp:TextBox>
<asp:Literal ID="ltlName" runat="server" ></asp:Literal>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtName" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
正在更新中...
</ProgressTemplate>
</asp:UpdateProgress>
</div>
</form>
后台代码
protected void txtName_TextChanged(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(2000); //为了看清楚UpdateProgress的过程
if (txtName.Text == "123")
{
ltlName.Text = "已经被注册";
}
else
{
ltlName.Text = "可以注册";
}
}
相关文档:
今天,有同事发现相关业务数据修改后,在IE6下还是显示修改前的值。但在其他浏览器和IE7、IE8下,没有这个问题。
原因:用ajax请求时,如果出现重复的URL,浏览器不会向服务器发送请求,而是根据之前相同的URL请求结果返回。原因就在于之前的请求及结果已经保存在了
缓存里,如果遇到相同URL时,结果是直接从缓存里取得。 ......
1,本例子实现一个Ajax更改数据的例子
如图:
1,新建xml文件;其内容如下:
<?xml version="1.0" encoding="utf-8"?>
<userinfo>
<user>
<id>I</id>
<name>wtq</name>
<password>123456</password>
<phone>0595-8553 ......
function saveObj(){
var userName = document.getElementById("userName").value;
checkUserName(userName);
}
//使用ajax实现页面无刷新功能;
var xmlHttpRequest;
function createXMLHttpRequest(){
if(windo ......
许多程序员在做业务开发时往往会在服务器端做用户信息的验证,有没有考虑过用jquery的ajax方法来验证登陆呢?且效果比在服务器端写代码来验证好的多,页面无刷新即可实现实现登陆验证,代码也简单。
现在下面贴出来的是很简单的用jquery的ajax方法来验证登陆的代码,适合刚接触jquery的朋友学习。
前台页面代码:
<he ......
原来用jQuery的ajax方式调用asp.net页面基本都是调用单个页面,由调用页面Response内容,而现在采用asp.net ajax后,我们则可以更完美的使用jQuery和asp.net结合了,代码如下:
<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Scripts>
<asp:ScriptReference Path="http ......