Application of AjaxPro

Source: Internet
Author: User

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;
}
}
}

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.