473,473 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
2 1961
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Li Weng | last post by:
Hi, I have a button (btnSearch) and its Click event sub btnSearch_Click. Clicking the button will trigger the event. But how do I trigger this event in code? I tried RaiseEvent btnSearch.Click...
6
by: Carlo Marchesoni | last post by:
I have an ASP.NET/C# solution, where I can perfectly cast something I stored in the session object to a class of mine (BackEnd), as this: ->be = (BackEnd)Session;<- But if I try to do the same:...
6
by: Beffmans | last post by:
Hi I want to hook the "back" event or "forward" event from a browser page. How can I trigger these events to my asp.net page? ch Beffmans *** Sent via Developersdex...
2
by: alain.hogue | last post by:
I known that by using the "Profile_MigrateAnonymous" event I can migrate my anonymous users profile to their authenticated account profile, but I would like to carry over some of the properties of...
8
by: Roger | last post by:
When I call the session.abandon() method, it calls the session_end event. When a user closes the browser or clicks the log off button, I can dispose of objects and abandon the session cleaning....
3
by: Morgan Cheng | last post by:
"Server.Transfer(Request.FilePath);" make server re-evaluate current page. In debugger, I found that though the page's OnPreInit is called, delegates attached in HttpModule is not executed. Why...
3
by: Mark Rae [MVP] | last post by:
"Lloyd Sheen" <a@b.cwrote in message news:uL5TPXPvIHA.1688@TK2MSFTNGP06.phx.gbl... Surely that will throw an exception because you're trying to populate a DataSet variable with an object...
1
by: =?Utf-8?B?R2Vvc3Ns?= | last post by:
Dear All, I try to change a master page in the OnPreInit in a asp.net page. protected override void OnPreInit(EventArgs e){ if ((bool)session){ this.MasterPageFile = "~/NewMaster.master"; }...
4
by: AndreH | last post by:
Good day, I have the a bit of an issue with retrieving an object from php's session. I set a session variable "user" from the class User as follows: $user = new User(); // ... do some stuff...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.