Click to See Complete Forum and Search --> : static member in codebehind


dannystommen
November 25th, 2008, 04:10 AM
in the codebehind page I have a static member. I noticed that when I open my page twice, they both use the same member. Example:

private static int TestInt = 0;

protected void Page_Load(object sender, EventArgs e) {
TestInt++;
Label1.Text = TestInt.ToString();
}

When I open the page in IE (not debug mode in Visual Studio, pae is hosted in IIS), the text of the label is 1. When I open in another browser the same page, the text of the label is 2, so it uses the same member.

But I open the page on the same computer. What happens if this page is opened from another computer, will the label of the text then be 3? Or is a new member created for this page?

I hope I made myself clear.

dannystommen
November 25th, 2008, 04:34 AM
I managed to access the page from another computer, and this also uses the same static member.

The reason I needed this to know is that the page is connected to an WCF host and can recieve a callback from the host. So every page needs to subscribe to the host, but this doesn't work when they all use the same member.

The reason I made it static is because on every page_load the service object needs to be initialized again and the subscription is gone.

What is the best way to solve this? after initialzing the the service object add it to the Session, and on page_load retrieve this service object from the session?