Monday, March 19, 2012

Popup Login control in ASP.NET Using Div and CSS (LightBox effect) code behind

Before study this article please study its part1 Popup Login control in ASP.NET Using Div and CSS .

In my previous post I have explained the Hoe to create Popup Login control in  ASP.NET  Using Div and CSS.Now am going to explain the Code behind (validating Username and password with respect to Database).

For this we need to Write the code in the c# Button click event.Add the following Button click event in Aspx file as well as code behind file.

Aspx Changes :
Add the new <tr> after the "txtpwd"
<tr>
<td align="right">
</td>
<td>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
</tr>
 Add the Button click event  to Button2:
<asp:Button ID="Button2" runat="server" Text="Sign In" class="button2" OnClick="Button1_Click" />
Add the Runat="Server" tag to the light Div :
 <div id="light" class="white_content" runat="server">

code Behind :
 
     protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=DBServername;Initial Catalog=DbRegistration;Integrated Security=True");
            string s = "select [Username],[UPassword] from tblRegistration where [Username]='" + txtUser.Text + "' AND [UPassword]='" + txtPwd.Text + "'";
            SqlCommand cmd = new SqlCommand(s, con);
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            if (dt.Rows.Count == 0)
            {
                light.Style.Add("Display", "block");
                fade.Style.Add("Display", "block");
                Label1.Text = "In Correct UserID and Password";
            }
            else if (dt.Rows.Count!= 0)
            {
                light.Style.Add("Display", "none");
                fade.Style.Add("Display", "none");
                Response.Write("Logged In Successfully");
            }
        }


The above check the the entered User name and password are correct in the Database or not.If it is correct it will displays the old page.If it not correct then it will show the error :

Out Put :




3 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete