Friday, March 16, 2012

Popup Login control in ASP.NET Using Div and CSS

Author : Prakash Pradeep Gopu
In this am going to explain the Popup login in using Div and CSS.
Open Visual studio 2010 or 2008 and create a new website and create new webpage say Popuplogin.aspx. Paste the following html code.
<html xmlns="">
<head runat="server">
    <style type="text/css">
.black_overlay {
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
-moz-opacity: 0.8;
filter: alpha(opacity=80);
position: absolute;
top: 25%;
left: 35%;
width: 35%;
padding: 0px;
border: 0px solid #CC9933 ;
background-color: white;
overflow: auto;
font-family:Arial, Helvetica, sans-serif;
border:1px solid #CC9933 ;
 background-color:   #CC9933 ;
 border:1px solid #7f9db9;
    <form id="form1" runat="server">
    <a href = "javascript:void(0)" class="toplink" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">Login</a>
                                <div id="light" class="white_content">
 <table cellpadding=0 cellspacing=0 border=0 style="background-color:#CC9933 ;" width="100%"><tr><td height="16px"><a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'">
     <img src="images/close-icon.png"
         style="border-style: none; border-color: inherit; border-width: 0px; height: 17px; width: 16px;"
<tr><td style="padding-left:16px;padding-right:16px;padding-bottom:16px">
<table align="center"  border="0" cellpadding="0" cellspacing="0" style="background-color:#fff" width="100%">
<td align="center" colspan="2" class="headertext" >Login Form </td>
<tr><td align="center">
<td align="right" class="bot_text">Username:</td>
<td><asp:TextBox ID="_txtUserid" runat="server"></asp:TextBox></td>
</tr><tr><td height="10px"></td><td>
 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                                    ControlToValidate="_txtUserid" ErrorMessage="User ID Required"
                                    ValidationGroup="a" CssClass="content3"></asp:RequiredFieldValidator>
<tr><td align="right" class="bot_text">Password:</td>
<td><asp:TextBox ID="_txtPassword" runat="server" TextMode="Password"></asp:TextBox>
<tr><td height="10px"></td>
 <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                                    ControlToValidate="_txtPassword" ErrorMessage="Password Required"
                                    ValidationGroup="a" CssClass="content3"></asp:RequiredFieldValidator>
<td> </td><td><asp:Button ID="_btnLogin" runat="server" onclick="_btnLogin_Click" CssClass="button2" Text="Login" ValidationGroup="a" />
<tr><td height="10px"></td></tr>
<div id="fade" class="black_overlay"></div>

Save the page and run you will see the following output :

Undersatnding the code :
When you debug the code you will see the login link when you click it we are calling internally div with id  light using the following code.
<a href = "javascript:void(0)" class="toplink" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">Login</a>
There div light is a div consists of login form with username and passwords.and required field can write your own code for validating the username and pass word in the login control click event.

No comments:

Post a Comment