All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
Ajax简单客户登陆验证_[Asp.Net教程]

Writer: delv Article type: Programming skills(编程技巧) Time: 2014/1/6 8:47:30 Browse times: 374 Comment times: 0

Ajax简单客户登陆验证_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

Ajax简单客户登陆验证_[Asp.Net教程]























服务器端操作方便之处我就不吹了,地球人都知道,它最烦莫过于页面刷新,头都被刷晕了,而且他在刷新的时候,还触发服务器端的事件(解决方案:http://skylaugh.cnblogs.com/archive/2006/06/05/418010.html),现在Ajax的出现,他们的结合是发展的必然!




一、介绍一下Ajax在Asp.Net中的基本使用
1、在工程中引入Ajax.dll文件。
  Ajax.dll实现XmlHttpRequest请求服务器的实现细节。.net项目中,添加上对其的引用,就可以进




行相应封装操作了。




2、在web.config中设置HttpHandle
  


3、在 与间加入一些引用如下:






二、介绍正题-用户登录验证
1、前台Html:














usename















pwd



























2、引用Js文件








login.Js文件
// 提取控件值
function getValueById(pObjID){
var obj=document.getElementById(pObjID);
try{
return obj.value;
}catch(e){
alert("控件:"+pObjID+" 不存在,或没有value属性");
}
}




function Login(obj)
{
this.OBJ = obj;
this.GetLogin=function()
{
var returnValue;
var username=getValueById('txtUsername');
var password=getValueById('txtPassword');
if(!username||!password)
{
alert('请输入用户名与密码!');
return;
}
try
{
returnValue=this.OBJ.Login(username,password).value;
}catch(e)
{
alert('登录出错,请稍后再试或与管理员联系');
}
switch(returnValue)
{

case 1:
alert('对不起,您输入的用户名或密码不正确或者不是管理员!');
break;
case 0:
alert('管理员登录成功!');
window.document.location.href('../Error.aspx');
break;
default:
alert('登录失败,请稍后再试或与管理员联系'+returnValue);
break;
}
}
}




3、.cs文件




private void Page_Load(object sender, System.EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(testAjax));
}




[Ajax.AjaxMethod()]
public int Login(string username,string password)
{
// 管理员登陆入口
Action.Common.CDB cdb = new Action.Common.CDB();
if("admin"==cdb.ExeScalar("select upower from users where




uname='"+username+"' and upwd='"+password+"'"))
return 0;
else
return 1;
}




来源:网络














































There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.