How to Create Simple Login Form Using Asp.Net C#



  Html Coding 

  <html xmlns="">
<head id="Head1" runat="server">
    <form id="form1" runat="server">
            <asp:Label ID="Label1" runat="server" Text="UserName"></asp:Label>
                <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
            <asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
                <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
        <tr><td colspan ="2">
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Login" />

C# Coding

 protected void Button1_Click(object sender, EventArgs e)
        query = "select username,password from register  where
         username='"+txtUsername .Text+"' and password='"+txtPassword .Text+"'";
        cmd = new SqlCommand(query, con);
         rd = cmd.ExecuteReader();
        if (rd.Read())

            Response.Write("<script>alert('Invalid Username or Password')</script>");

First - Add New WebForm - Selec tLabels & Textboxes & Button  - textbox Change Id name  

       Next - Login Button - Double Click  - Go to Coding Page


Next - Coding Page Add NameSpaces & Database Connection in Public

 Next - Add new WebForm Change Name homepage.aspx  &  Write Welcome To homepage


  Login Button - Double Click - Write the Coding Select Query using from Register Table
            Reader rd check  username & password  If Correct goto  Homepage Or  Else Part Popup Message Display


Next - F5 Click - Run the Program  Correct  Username & Password  Given Go to  homepage.aspx

                               Control Go to - homepage.aspx

                               Given input is Wrong


                                    Show the Popup Message


Post a Comment