Reputation: 32301
I know this is pretty basic, but why do variables in master pages lose their value in the child pages?
For example if I have
[masterpage]
public string userId
... set userId in masterpage
[child page]
Master.userId // userId will always be empty?
Upvotes: 0
Views: 1042
Reputation: 511
i'd say try using Session["userId"]="..."
and in otherpage.aspx =>Session[userId].ToString()
will get the value
Upvotes: 1
Reputation: 13682
Because this is a stateless paradigm. If you want to maintain those values between post backs you have only a few options:
Upvotes: 2
Reputation: 12554
Don't use master pages to store information about users -- it won't persist there after the re-load of your page.
If you need to store some user-specific information use the Session
object to store it.
Here is an example.
Upvotes: 3