I am having one doubt regarding the use of static variable in Asp.net pages.
I am having one page say UserDetails.aspx.
In this page, I have one static variable to store some data specific to a user. So, will this variable be shared across multiple user or a separate variable will be created for each user?
public partial class UserDetails : System.Web.UI.Page
{
static int numberOfReviews=0;
protected void Page_Load(object sender, EventArgs e)
{
numberOfReviews= GetReviews();
}
}
Here, will numberOfReviews be specific to each user or will be shared?
numberOfReviews
static variable scope is application wide.
numberOfReviewswill be shared among all users. you need to useSessionto store per user, so it is accessible in all pages. On the other hand, if you just need it on a specific page, you can save it inViewStateand can get it in post back.