Asp+ajax Simple Client Login verification _ajax related
Source: Internet
Author: User
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
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
}
}
}
[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
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