Click here to Skip to main content
13,254,154 members (58,644 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

6.4K views
1 bookmarked
Posted 11 Oct 2013

HTML login page using JQuery

, 11 Oct 2013
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"><br /><<span class="tag">html</span><span class="attr"> xmlns=</span><span class="attrv">"http://www.w3.org/1999/xhtml"</span>><br /><<span class="tag">head</span>><br />    <<span class="tag">title</span>>Html login page</<span class="tag">title</span>><br />    <<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>><br />    <<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>><br />        function login() {
var uid = $("#uid").value;
var pwd = $("#pwd").value;<br />      //var uid = document.getElementById('uid').value;<br />     //var pwd = document.getElementById('pwd').value;<br />      $('#resultspan').load('ajaxLogin.aspx?uid='+uid+'&pwd='+pwd);<br />    }<br />    </<span class="tag">script</span>><br /></<span class="tag">head</span>><br /><<span class="tag">body</span>><br /><<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>><br /><<span class="tag">tr</span>><br /> <<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>><br /></<span class="tag">tr</span>><br /><<span class="tag">tr</span>><br /> <<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>><br /></<span class="tag">tr</span>><br /><<span class="tag">tr</span>><br /> <<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>><br /></<span class="tag">tr</span>><br /><<span class="tag">tr</span>><br /> <<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>><br /></<span class="tag">tr</span>><br /></<span class="tag">table</span>><br /></<span class="tag">body</span>><br /></<span class="tag">html</span>><br />
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<br />{<br />    <span class="kwd">protected void</span> Page_Load(<span class="kwd">object</span> sender, EventArgs e)<br />    {<br />        <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>)<br />        {<br />            <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>)<br />                Response.Write(<span class="st">"Login successful"</span>);<br />            <span class="kwd">else</span><br />                Response.Write(<span class="st">"Login failure"</span>);<br />        }<br />    }<br />}

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
This member doesn't quite have enough reputation to be able to display their biography and homepage.
Group type: Collaborative Group

764 members


You may also be interested in...

Pro
Pro

Comments and Discussions

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