【 tulaoshi.com - Javascript 】
                             
                             服务器端操作方便之处我就不吹了,地球人都知道,它最烦莫过于页面刷新,头都被刷晕了,而且他在刷新的时候,还触发服务器端的事件(解决方案: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 
    <httpHandlers 
      <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/ 
    </httpHandlers 
    3、在 <HEAD与</HEAD间加入一些引用如下: 
    <script src="http://img.jcwcn.com/attachment/portal"CSS/myStyle.css" type="text/css" rel="stylesheet"  
    <script src="http://img.jcwcn.com/attachment/portal" type="text/javascript"</script  
    <script src="http://img.jcwcn.com/attachment/portal" type="text/javascript"</script  
    二、介绍正题-用户登录验证 
    1、前台Html: 
<form id="Form1" method="post" runat="server" action="" onsubmit="login.GetLogin();return false;"    
    <TABLE id="Table1"  cellSpacing="1" cellPadding="1" width="300" border="1" 
     <TR 
      <TD</TD 
      <TD<INPUT type="text"  id="txtUsername"usename</TD 
     </TR 
     <TR 
      <TD</TD 
      <TD<INPUT type="password"  id="txtPassword"pwd</TD 
     </TR 
     <TR 
      <TD</TD 
      <TD<INPUT type="submit" value="登陆"</TD 
     </TR 
    </TABLE 
  </form 
    2、引用Js文件 
<SCRIPT language="javascript" src="http://img.jcwcn.com/attachment/portal" type="text/javascript"</SCRIPT 
  <script language="javascript" 
  window.onload = function() 
    { 
       login=new Login(testAjax); 
      } 
  </script 
   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; [next]
 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(’登录出错,请稍后再试或与管理员联系’); 
                        来源:http://www.tulaoshi.com/n/20160129/1482330.html