You have made a simple login with AjaxPro, and the application AjaxPro needs to be modified in the configuration file.
Add the following code to the <system. web> </system. web> label
<HttpHandlers>
<Add verb = "POST, GET" path = "ajaxpro/*. ashx" type = "AjaxPro. AjaxHandlerFactory, AjaxPro.2"/>
</HttpHandlers>
The configuration file can be applied after modification. See the following login operations
HTML:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "ajaxpro. aspx. cs" Inherits = "Login_ajaxpro" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
<Script type = "text/javascript">
Function Login_ButtonClick (){
Var username = document. getElementById ("Text1"). value;
Var password = document. getElementById ("Text2"). value;
Document. getElementById ("loading"). style. display = "block ";
Login_ajaxpro.UserName (username, password, CallBackServer );
}
Function CallBackServer (res ){
Var success = res. value;
Document. getElementById ("loading"). style. display = "none ";
If (success ){
Alert ("Login successful ");
}
Else {
Alert ("Logon Failed. Please check your username and password! ");
}
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Input id = "Text1" type = "text"/>
<Input id = "Text2" type = "text"/>
<Input id = "Button1" type = "button" value = "button" onclick = "Login_ButtonClick ();"/>
<Div id = "loading" style = "display: none;"> logging in... </div>
</Div>
</Form>
</Body>
</Html>
. CS
Using System;
Using System. Data;
Using System. Configuration;
Using System. Collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using AjaxPro;
Using System. Data. SqlClient;
Public partial class Login_ajaxpro: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
AjaxPro. Utility. RegisterTypeForAjax (typeof (Login_ajaxpro); // register AjaxPro
}
[AjaxPro. AjaxMethod]
Public bool UserName (string username, string password)
{
System. Threading. Thread. Sleep (3000 );
String strName = username. ToString ();
String strPWD = password. ToString ();
String strConn = ConfigurationSettings. etettings ["connectinString"]. ToString ();
SqlConnection conn = new SqlConnection (strConn );
Conn. Open ();
SqlCommand com = new SqlCommand ();
Com. CommandText = "select * from users where username = '" + strName + "' and password = '" + strPWD + "'";
Com. Connection = conn;
SqlDataReader da = com. ExecuteReader ();
If (da. Read ())
{
Conn. Close ();
Return true;
}
Else
{
Conn. Close ();
Return false;
}
}
}