Today, we are going to make a login page, just another simple web form. You can easily implement this concept anywhere in .NET applications. I have used some controls to build the login form in a .NET application.
- Text Box
- Label and Button
Please follow these steps to make this application.
Step 1
First, open your Visual Studio -> File -> New -> Website -> ASP.NET Empty website and click OK. Now, open Solution Explorer and go to Add New Item -> Web form -> click Add.
Step 2
Now, make a Login page like the one given below.
Step 1
First, open your Visual Studio -> File -> New -> Website -> ASP.NET Empty website and click OK. Now, open Solution Explorer and go to Add New Item -> Web form -> click Add.
Step 2
Now, make a Login page like the one given below.
.aspx or design page (front-end)
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Login Form</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <table>
- <tr>
- <td> Username: </td>
- <td>
- <asp:TextBox ID="txtUserName" runat="server" />
- <asp:RequiredFieldValidator ID="rfvUser" ErrorMessage="Please enter Username" ControlToValidate="txtUserName" runat="server" /> </td>
- </tr>
- <tr>
- <td> Password: </td>
- <td>
- <asp:TextBox ID="txtPWD" runat="server" TextMode="Password" />
- <asp:RequiredFieldValidator ID="rfvPWD" runat="server" ControlToValidate="txtPWD" ErrorMessage="Please enter Password" /> </td>
- </tr>
- <tr>
- <td> </td>
- <td>
- <asp:Button ID="btnSubmit" runat="server" Text="Submit" /> </td>
- </tr>
- </table>
- </div>
- </form>
- </body>
- </html>
Now, create an event for click button, such as - onclick="<>".
- onclick="btnSubmit_Click"
So, our button tag will be like <asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />. And in login.aspx.cs page, we need to write the following code.
C# Code --Code behind(Aspx.cs)
- using System;
- using System.Data;
- using System.Data.SqlClient;
- using System.Configuration;
- protected void btnSubmit_Click(object sender, EventArgs e) {
- SqlConnection con = newSqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
- con.Open();
- SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName =@username and Password=@password", con);
- cmd.Parameters.AddWithValue("@username", txtUserName.Text);
- cmd.Parameters.AddWithValue("@password", txtPWD.Text);
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- DataTable dt = new DataTable();
- da.Fill(dt);
- if (dt.Rows.Count > 0) {
- Response.Redirect("Details.aspx");
- } else {
- ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
- }
- }
Now, for connecting it with the database, write the database connection string like the following.
Web Config
Web Config
- <connectionStrings>
- <add name="dbconnection" connectionString="Data Source=BrajeshKr;Integrated Security=true;Initial Catalog=MyDB" /> </connectionStrings>
That's it. Now, our Login page is ready to be executed. You can download the code for this application and run that on your Visual Studio.

Brajesh KumarPosted Feb 13, 2017, 5:19 AM
Http://www.c-sharpcorner.com/blogs/login-form-in-angularjs-and-asp-net-mvc
Pravas RanjanPosted Feb 8, 2017, 6:09 AM
Hi Kumar once you post the article please share me the link thanks again Bhai.......
Pravas RanjanPosted Feb 8, 2017, 1:45 AM
Hello Kumar, i will definitely wait for your new upcoming article on Angular JS and MVC CRUD operation with bootstrap and one thing please make this article as simple as possible so that it can be very easy to understand for beginner as well as experience professional prospective ..... Thanks again Kumar for this nice and easy article......
garima kumariPosted Feb 7, 2017, 11:27 AM
Thanks @Brajesh keep posting article like this .Eagerly waiting for your next angular post.Great and simple
Anmol ChaudharyPosted Feb 7, 2017, 11:06 AM
Hi pravas biswal i think 1. You can use the Oracle data provider that comes with Microsoft, but I recommend using ODP.Net. It's best to use native libraries when possible since they are usually optimized better, at least in my experience. 2. You only need to configure the tnsnames.ora on the server, because the server is what's going to be handling the DB connections, not the client PCs (assuming that this is a MVC website).
Pravas RanjanPosted Feb 7, 2017, 6:17 AM
I am not using Sql server i am using Oracle and fetching db details from web.config please sugest
Pravas RanjanPosted Feb 7, 2017, 6:16 AM
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
Pravas RanjanPosted Feb 7, 2017, 6:15 AM
Kumar i am using Oracle Database and it is in another server and when i am running my application getting below error can you please tell me where is the problem
Pravas RanjanPosted Feb 7, 2017, 1:00 AM
Keep posting Article like this.................
Pravas RanjanPosted Feb 7, 2017, 12:59 AM
Hello Kumar Excellent Article but can you please add same topic using Angular JS and MVC with bootstrap...
Satyaprakash SamantarayPosted Jan 26, 2017, 10:27 PM
Put some screen shots as well as some output result for end user's better understanding....