Hi indradeo
Refer below sample code.
HTML
Default
<div>
<asp:Button ID="btnHome" Text="Home" runat="server" OnClick="OnHome" />
<asp:Button ID="btnDisplay" Text="Display" runat="server" OnClick="OnDisplay" />
</div>
Home
<asp:Label Id="lblName" runat="server" />
Display
<asp:Label ID="lblDisplay" runat="server"></asp:Label>
Code
C#
Default
protected void Page_Load(object sender, EventArgs e)
{
Session["Name"] = "Welcome to ASPSnippets";
}
protected void OnHome(object sender, EventArgs e)
{
Response.Redirect("Home.aspx");
}
protected void OnDisplay(object sender, EventArgs e)
{
Response.Redirect("Display.aspx");
}
Home
protected void Page_Load(object sender, EventArgs e)
{
string name = Session["Name"].ToString();
lblName.Text = name;
}
Display
protected void Page_Load(object sender, EventArgs e)
{
string name = Session["Name"].ToString();
lblDisplay.Text = name;
}
VB.NET
Default
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Session("Name") = "Welcome to ASPSnippets"
End Sub
Protected Sub OnHome(ByVal sender As Object, ByVal e As EventArgs)
Response.Redirect("Home")
End Sub
Protected Sub OnDisplay(ByVal sender As Object, ByVal e As EventArgs)
Response.Redirect("Display")
End Sub
Home
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim name As String = Session("Name").ToString()
lblName.Text = name
End Sub
Display
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim name As String = Session("Name").ToString()
lblDisplay.Text = name
End Sub
Screenshot