In modern web applications, managing user sessions across multiple browser tabs can be tricky, especially when you want to show dynamic user data in pop-ups like an application form. In this Blog, we’ll explore a common ASP.NET session issue and provide a robust solution step by step.
The Scenario
Imagine this situation:
Tab 1: User A logs in.
Tab 2: User B logs in in the same browser.
You return to Tab 1 and try to apply IPO.
Problem
The pop-up shows User A’s name (from page load).
Backend, however, processes User B’s session data (because the session is shared across tabs).
This mismatch can confuse users and cause data integrity issues.
Why This Happens
ASP.NET sessions are per browser, not per tab.
Tab 1: logs in as User A →
Session["ClientFname"] = "A".Tab 2: logs in as User B →
Session["ClientFname"] = "B".Both tabs now share the same session cookie.
Result: Frontend shows old cached data (User A), while the backend processes the latest session (User B).
Goal
We want to ensure that:
✅ The frontend popup always shows the correct client details.
✅ The backend request corresponds to the same user shown in the pop-up.
Solution: Fetch Data Dynamically from Backend
The most reliable approach is to fetch user session data dynamically from the server when the pop-up is triggered. This ensures the displayed data always matches the backend session.
Step 1. Add a WebMethod in ASP.NET
In your ASPX code-behind, create a WebMethod to return session data:
[System.Web.Services.WebMethod]
public static object GetClientSessionData()
{
try
{
string name = HttpContext.Current.Session["ClientFname"]?.ToString() ?? "";
string pan = HttpContext.Current.Session["Pan"]?.ToString() ?? "";
string dp = HttpContext.Current.Session["Depository"]?.ToString() ?? "";
return new
{
ClientFname = name,
Pan = pan,
Depository = dp
};
}
catch (Exception ex)
{
return new { Error = ex.Message };
}
}
Tip: You can also create a strong-typed class for clarity instead of returning an anonymous object.
Step 2. Call the WebMethod from JavaScript
When the user clicks Apply IPO, call the WebMethod to get the current session data:
function submitalldata() {
// Get UPI ID entered by user
var UPIID = document.getElementById("<%=txtupiid.ClientID%>").value;
// Call backend WebMethod to get session data
$.ajax({
type: "POST",
url: "ApplyIPO.aspx/GetClientSessionData",
data: '{}', // no parameters needed
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var data = response.d;
if (data.Error) {
alert("Error: " + data.Error);
return;
}
// Populate popup fields with session data
document.getElementById("clname").innerText = data.ClientFname;
document.getElementById("clpan").innerText = data.Pan;
document.getElementById("cldpid").innerText = data.Depository;
document.getElementById("clupi").innerText = UPIID;
document.getElementById("clupiname").innerText = data.ClientFname; // optional if needed
// Show popup modal dynamically
$('#conformModalpopup').modal('show');
},
error: function (xhr, status, error) {
console.error("Error fetching session data:", error);
}
});
// Prevent full postback
return false;
}

Join the conversation! Your thoughts help the community grow.