Hi Akhter,
Please refer below sample and Use that master page's HTML & Code to your other page also.
HTML
Default
<table>
<tr>
<td>UserName :</td>
<td><asp:TextBox runat="server" ID="txtUserName" /></td>
</tr>
<tr>
<td>Password :</td>
<td><asp:TextBox runat="server" ID="txtPassword" /></td>
</tr>
<tr>
<td><asp:Button ID="btnSend" Text="Send" runat="server" OnClick="Send" /></td>
</tr>
</table>
Master
<table>
<tr>
<td>UserId :</td>
<td><asp:Label runat="server" ID="lblUserId" /></td>
</tr>
</table>
Namespaces
C#
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.Data.SqlClient
Imports System.Configuration
Code
C#
Default
protected void Send(object sender, EventArgs e)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("SELECT UserId, Username, Password, RoleId From Users WHERE UserName = @UserName and Password = @Password", con))
{
cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
Session["UserName"] = sdr["Username"];
Session["UserId"] = sdr["UserId"];
Session["Password"] = sdr["Password"];
Session["RoleId"] = sdr["RoleId"];
}
con.Close();
}
}
if (Session["RoleId"].ToString() == "1")
{
Response.Redirect("Master.aspx");
}
else if (Session["RoleId"].ToString() == "2")
{
Response.Redirect("Input.aspx");
}
else if (Session["RoleId"].ToString() == "3")
{
Response.Redirect("Dispatch.aspx");
}
}
Master
protected void Page_Load(object sender, EventArgs e)
{
lblUserId.Text = Session["UserId"].ToString();
}
VB.Net
Default
Protected Sub Send(ByVal sender As Object, ByVal e As EventArgs)
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand("SELECT UserId, Username, Password, RoleId From Users WHERE UserName = @UserName and Password = @Password", con)
cmd.Parameters.AddWithValue("@UserName", txtUserName.Text)
cmd.Parameters.AddWithValue("@Password", txtPassword.Text)
con.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader()
If sdr.Read() Then
Session("UserName") = sdr("Username")
Session("UserId") = sdr("UserId")
Session("Password") = sdr("Password")
Session("RoleId") = sdr("RoleId")
End If
con.Close()
End Using
End Using
If Session("RoleId").ToString() = "1" Then
Response.Redirect("MasterVB.aspx")
ElseIf Session("RoleId").ToString() = "2" Then
Response.Redirect("InputVB.aspx")
ElseIf Session("RoleId").ToString() = "3" Then
Response.Redirect("DispatchVB.aspx")
End If
End Sub
Master
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
lblUserId.Text = Session("UserId").ToString()
End Sub
Screenshot