Click here to Skip to main content
Click here to Skip to main content

HTML login page using JQuery

, 11 Oct 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Here is the login form it has user id and password text boxes. When user clicks Login button, it calls ajaxLogin.aspx page in background process

Editorial Note

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

Here is the login form it has user id and password text boxes. When user clicks Login button, it calls ajaxLogin.aspx page in background process using JQuery and it returns login success or failure message and prints in one span element.

Example uses jquery.js file. You can download that file from here.

File: Login.html

<<span class="tag">!DOCTYPE</span> html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<<span class="tag">html</span><span class="attr"> xmlns=</span><span class="attrv">"http://www.w3.org/1999/xhtml"</span>>
<<span class="tag">head</span>>
    <<span class="tag">title</span>>Html login page</<span class="tag">title</span>>
    <<span class="tag">script</span><span class="attr"> language=</span><span class="attrv">"javascript"</span><span class="attr"> type=</span><span class="attrv">"text/javascript"</span><span class="attr"> src=</span><span class="attrv">"jquery.js"</span>></<span class="tag">script</span>>
    <<span class="tag">script</span><span class="attr"> language=</span><span class="attrv">"javascript"</span><span class="attr"> type=</span><span class="attrv">"text/javascript"</span>>
        function login() {
var uid = $("#uid").value;
var pwd = $("#pwd").value;
      //var uid = document.getElementById('uid').value;
     //var pwd = document.getElementById('pwd').value;
      $('#resultspan').load('ajaxLogin.aspx?uid='+uid+'&pwd='+pwd);
    }
    </<span class="tag">script</span>>
</<span class="tag">head</span>>
<<span class="tag">body</span>>
<<span class="tag">table</span><span class="attr"> width=</span><span class="attrv">"65%"</span><span class="attr"> cellpadding=</span><span class="attrv">"2"</span><span class="attr"> cellspacing=</span><span class="attrv">"2"</span>>
<<span class="tag">tr</span>>
 <<span class="tag">td</span><span class="attr"> colspan=</span><span class="attrv">"2"</span>><<span class="tag">span</span><span class="attr"> id=</span><span class="attrv">"resultspan"</span>></<span class="tag">span</span>></<span class="tag">td</span>>
</<span class="tag">tr</span>>
<<span class="tag">tr</span>>
 <<span class="tag">td</span><span class="attr"> width=</span><span class="attrv">"25%"</span>>User Id:</<span class="tag">td</span>><<span class="tag">td</span>><<span class="tag">input</span><span class="attr"> type=</span><span class="attrv">"text"</span><span class="attr"> id=</span><span class="attrv">"uid"</span> /></<span class="tag">td</span>>
</<span class="tag">tr</span>>
<<span class="tag">tr</span>>
 <<span class="tag">td</span><span class="attr"> width=</span><span class="attrv">"25%"</span>>Password:</<span class="tag">td</span>><<span class="tag">td</span>><<span class="tag">input</span><span class="attr"> type=</span><span class="attrv">"password"</span><span class="attr"> id=</span><span class="attrv">"pwd"</span> /></<span class="tag">td</span>>
</<span class="tag">tr</span>>
<<span class="tag">tr</span>>
 <<span class="tag">td</span><span class="attr"> colspan=</span><span class="attrv">"2"</span><span class="attr"> align=</span><span class="attrv">"center"</span>><<span class="tag">input</span><span class="attr"> type=</span><span class="attrv">"button"</span><span class="attr"> value=</span><span class="attrv">"Login"</span><span class="attr"> onclick=</span><span class="attrv">"login();"</span> /></<span class="tag">td</span>>
</<span class="tag">tr</span>>
</<span class="tag">table</span>>
</<span class="tag">body</span>>
</<span class="tag">html</span>>
Here it checks that if user id is “test” and password is “test” then it does return successful login, here you can call your database and to find the login result.

File:  ajaxLogin.aspx.cs

<span class="kwd">public</span> partial <span class="kwd">class</span> ajaxLogin : System.Web.UI.Page
{
    <span class="kwd">protected void</span> Page_Load(<span class="kwd">object</span> sender, EventArgs e)
    {
        <span class="kwd">if</span> (Request.QueryString[<span class="st">"uid"</span>] != <span class="kwd">null</span> && Request.QueryString[<span class="st">"uid"</span>] != <span class="kwd">null</span>)
        {
            <span class="kwd">if</span> (Request.QueryString[<span class="st">"uid"</span>].ToString() == <span class="st">"test"</span> && Request.QueryString[<span class="st">"pwd"</span>].ToString() == <span class="st">"test"</span>)
                Response.Write(<span class="st">"Login successful"</span>);
            <span class="kwd">else</span>
                Response.Write(<span class="st">"Login failure"</span>);
        }
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

ASP.NET Community

United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.
 
The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
Group type: Collaborative Group

490 members


Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150327.1 | Last Updated 11 Oct 2013
Article Copyright 2013 by ASP.NET Community
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid