467,885 Members | 1,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,885 developers. It's quick & easy.

No event trigger after casting session variable in OnPreInit

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??
Sep 15 '08 #1
  • viewed: 1827
Share:
2 Replies
becuase casting a null to bool throws an exception, and stops page processing.

-- bruce (sqlwork.com)
"Geossl" wrote:
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??

Sep 15 '08 #2
As I have mentioned, the session variable is guaranteed being assinged. Not
null pointer exception....

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

-- bruce (sqlwork.com)
"Geossl" wrote:
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??
Sep 16 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Li Weng | last post: by
6 posts views Thread by Carlo Marchesoni | last post: by
6 posts views Thread by Beffmans | last post: by
8 posts views Thread by Roger | last post: by
3 posts views Thread by Morgan Cheng | last post: by
4 posts views Thread by AndreH | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.