문제

I declared in master page load:

Session["sessionString"] = "stringX";

in my web page on load also, i call it

string sessionString= (string)Session["sessionString"];

i debug and value in web page is "" what is wrong?

도움이 되었습니까?

해결책 2

JW Lim is correct...content page's load event will fire before Master page load.

@user3445314 , you can use "Session_Start" event in Global.asax and set values same as you set in master page.

"Session_Start" event fires first and then your content page load event occur.

I hope this may be solve your problem

다른 팁

The Page_Load event of a content page is called before the Page_Load event of the master page (see this SO answer and MSDN article). Hence, when you call

string sessionString= (string)Session["sessionString"];

in your web page, Session["sessionString"] does not contain any value yet and defaults to an empty string.

As a workaround, you could set the value of Session["sessionString"] on the Init or PreLoad events of your master page.

Declare Session in Master PreRender

protected override void OnPreRender(EventArgs e)
{
   Session["sessionString"] = "stringX";
}

And get it by ContetPage OnUnload event

protected override void OnUnload(EventArgs e)
{
   string sessionString= (string)Session["sessionString"];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top