Ajax Simple Client Login verification

Source: Internet
Author: User
Tags add net reference return string window client
Ajax

Server-side ease of operation I do not blow, the Earth people know, it is the most annoying than the page refresh, the head was brushed dizzy, and he refreshed, but also triggered the server side of the event (solution: http://skylaugh.cnblogs.com/archive/2006/06 /05/418010.html), now the advent of Ajax, their integration is the inevitable development!

First, the introduction of Ajax in the basic use of ASP.net
1, the introduction of Ajax.dll documents in the project.
Ajax.dll Implement the XMLHttpRequest request server implementation details.. NET project, add a reference to it, you can enter the

The line encapsulates the operation accordingly.

2. Set up Httphandle in Web.config
<add verb= "Post,get" path= "Ajax/*.ashx" type= "Ajax.pagehandlerfactory, Ajax"/>
3. Add some references between <HEAD> and </HEAD> as follows:
<script src=js/xml.js></script>
<link href= "Css/mystyle.css" type= "Text/css" rel= "stylesheet" >
<script src= "/httpforajax/ajax/common.ashx" type= "Text/javascript" ></script>
<script src= "/httpforajax/ajax/ttyu.ajaxdata,httpforajax.ashx" type= "Text/javascript" ></script>

Second, the introduction of the subject-User login verification
1, foreground HTML:
<form id= "Form1" method= "POST" runat= "Server" action= "" >
<table id= "Table1" cellspacing= "1" cellpadding= "1" width= "+" 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= "Landing" ></TD>
</TR>
</TABLE>
</form>

2, the reference JS file

<script language= "javascript" src= "Login.js" type= "Text/javascript" ></SCRIPT>
<script language= "JavaScript" >
Window.onload = function ()
{
Login=new Login (Testajax);
}
</script>

Login. JS file
Extracting control values
function Getvaluebyid (Pobjid) {
var Obj=document.getelementbyid (Pobjid);
try{
return obj.value;
}catch (e) {
Alert ("Control: +pobjid+" does not exist, or has no Value property);
}
}

function Login (obj)
{
This. obj = obj;
This. Getlogin=function ()
{
var returnvalue;
var Username=getvaluebyid (' txtUserName ');
var Password=getvaluebyid (' Txtpassword ');
if (!username| |! Password
{
Alert (' Please enter your username and password! ');
Return
}
Try
{
Returnvalue=this. Obj. Login (Username,password). value;
}catch (e)
{
Alert (' Login error, please try again later ' or contact the Administrator ');
}
Switch (returnvalue)
{

Case 1:
Alert (' Sorry, the username or password you entered is incorrect or not an administrator! ');
Break
Case 0:
Alert (' Admin login successful! ');
Window.document.location.href ('.. /error.aspx ');
Break
Default
Alert (' Login failed, please try again later or contact the Administrator ' +returnvalue ');
Break
}
}
}

3. cs file

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

[Ajax.ajaxmethod ()]
public int Login (string username,string password)
{
Admin Login Entry
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;
}

Http://skylaugh.cnblogs.com/archive/2006/06/14/426029.html



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.