Introduction:
Hi guys.. this is Sairam, In this post I will explain How to create a login page in asp.net with Bootstrap using c#.net and vb.net.Description:
- Create the SQL Server database and create table MDB_Memberlogin.
CREATE TABLE
[dbo].[MDB_Memberlogin](
[sno] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](50) NULL,
[pwd] [varchar](50) NULL,
[mobile] [varchar](20) NULL,
[status] [char](1) NULL,
[regdt] [smalldatetime] NULL
)
login table in sqlserver |
In design headder part add the bootstrap css and js shown in below.
<linkrel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"/>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
In the login.aspx page write below code
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="index.aspx.cs"Inherits="index"%>ASPDOTNET SAIRAM-Loginpage demo
and inside the double click event of the login button write following code in Login.aspx.cs
C# Code:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class login : System.Web.UI.Page { SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionIEATDOTNET"].ToString()); SqlCommand cmd = new SqlCommand(); SqlDataReader dr;
protected void btnLogin_Click(object sender, EventArgs e) { cmd.Connection = con; con.Open(); cmd.CommandText = "select sno,name from MDB_Memberlogin where mobile=@mobileno and pwd=@pwd and status='A'"; cmd.Parameters.AddWithValue("@mobileno", txtmobile.Text.Replace("'", "")); cmd.Parameters.AddWithValue("@pwd", txtpwd.Text.Replace("'", "")); dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { Session["name"] = dr["name"].ToString(); Response.Redirect("page2.aspx"); } } else { lblmsg.Text = "Invalid Mobile/password"; } dr.Close(); con.Close(); } }
VB.NET Code:
Imports System.Data.SqlClient Imports System.Data Imports System.Web.UI.WebControls Imports System.Web.UI Imports System.Web Imports System.Linq Imports System.Collections.Generic Imports System Public Partial Class login Inherits System.Web.UI.Page Private con As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionIEATDOTNET").ToString()) Private cmd As New SqlCommand() Private dr As SqlDataReader
Protected Sub btnLogin_Click(sender As Object, e As EventArgs) cmd.Connection = con con.Open() cmd.CommandText = "select sno,name from MDB_Memberlogin where mobile=@mobileno and pwd=@pwd and status='A'" cmd.Parameters.AddWithValue("@mobileno", txtmobile.Text.Replace("'", "")) cmd.Parameters.AddWithValue("@pwd", txtpwd.Text.Replace("'", "")) dr = cmd.ExecuteReader() If dr.HasRows Then While dr.Read() Session("name") = dr("name").ToString() Response.Redirect("page2.aspx") End While Else lblmsg.Text = "Invalid Mobile/password" End If dr.Close() con.Close() End Sub End Class
In page2.aspx of page_load event, write the following code
add label in design page
<asp:Label ID="Label1" runat="server" CssClass="h2 text-primary"></asp:Label>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class page2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { Label1.Text = "Welcom to Mr/Mrs " + Session["name"]; } } }
In Web.Config file
Result:
Login demo using bootstrap in asp.net |
Share the effort and feel free to post comments/suggestions. I love it to hear from you.
EmoticonEmoticon