No event trigger after casting session variable in OnPreInit

G

Geossl

Dear All,
I try to change a master page in the OnPreInit in a asp.net page.
(Session variable is guaranteed to have been assigned)

protected override void OnPreInit(EventArgs e){
if ((bool)session["IsNew"]){
this.MasterPageFile = "~/NewMaster.master";
}
else{
this.MasterPageFile = "~/OrigianlMaster.master";
}
base.OnPreInit(e)
}

But after this, the page does not trigger any other event. I try to trace to
the problem , and when I remove the casting of the session variable,
if ((bool)session["IsNew"]){
to
if (session["IsNew"] == null)

then, everything works fine again.

Why casting a session variable will inhibit the triggering of other events
in the page??
 
B

bruce barker

becuase casting a null to bool throws an exception, and stops page processing.

-- bruce (sqlwork.com)
 
G

Geossl

As I have mentioned, the session variable is guaranteed being assinged. Not
null pointer exception....



bruce barker said:
becuase casting a null to bool throws an exception, and stops page processing.

-- bruce (sqlwork.com)


Geossl said:
Dear All,
I try to change a master page in the OnPreInit in a asp.net page.
(Session variable is guaranteed to have been assigned)

protected override void OnPreInit(EventArgs e){
if ((bool)session["IsNew"]){
this.MasterPageFile = "~/NewMaster.master";
}
else{
this.MasterPageFile = "~/OrigianlMaster.master";
}
base.OnPreInit(e)
}

But after this, the page does not trigger any other event. I try to trace to
the problem , and when I remove the casting of the session variable,
if ((bool)session["IsNew"]){
to
if (session["IsNew"] == null)

then, everything works fine again.

Why casting a session variable will inhibit the triggering of other events
in the page??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top