Avoid execution of "Page_Load" of controls contained in MultiViewViews

D

DC

Hi,

the subject says it all. Since visible=false controls will still run
though Page_Load, I was hoping that the MultiView would somehow manage
to avoid a Page_Load of controls in its inactive Views. But of course
it does not.

I guess a safe way to avoid Page_Load is to only add the controls at
runtime into the activated view. Which of course neglects the beauty
of editing the layout if several views in one ascx.

Is there a more elegant way or at least a way to safely jump out of
Page_Load of the control (without checking the state of the parents,
please - since the control is not supposed to work in a View only).

TIA for any hint,

Regards
DC
 
D

Dave Bush

I suppose you could put them in an ascx file and dynamically load them
using LoadControl() but, the only way this will work is if you never
switch views as part of a post back OR you don't use viewstate.

The reason it loads all of the controls is so that it can re-establish
the state of the objects.

-----Original Message-----
From: DC [mailto:[email protected]]
Posted At: Wednesday, November 28, 2007 10:47 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Avoid execution of "Page_Load" of controls contained in
MultiView Views
Subject: Avoid execution of "Page_Load" of controls contained in
MultiView Views

Hi,

the subject says it all. Since visible=false controls will still run
though Page_Load, I was hoping that the MultiView would somehow manage
to avoid a Page_Load of controls in its inactive Views. But of course
it does not.

I guess a safe way to avoid Page_Load is to only add the controls at
runtime into the activated view. Which of course neglects the beauty
of editing the layout if several views in one ascx.

Is there a more elegant way or at least a way to safely jump out of
Page_Load of the control (without checking the state of the parents,
please - since the control is not supposed to work in a View only).

TIA for any hint,

Regards
DC
 
S

Scott Roberts

Is there a more elegant way or at least a way to safely jump out of
Page_Load of the control (without checking the state of the parents,
please - since the control is not supposed to work in a View only).

I believe that the "Visible" property automatically checks the visibility of
parent/container controls. So you could try:

public void Page_Load(blah,blah,blah)
{
if (this.Visible)
{
DoYourWork();
}
}
 
D

DC

I believe that the "Visible" property automatically checks the visibility of
parent/container controls. So you could try:

public void Page_Load(blah,blah,blah)
{
if (this.Visible)
{
DoYourWork();
}



}- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Thank you, Scott. This works in most situations. It is however
unreliable, because visibility of the control may be changed after the
Page_Load (but before Render).
 
D

DC

I suppose you could put them in an ascx file and dynamically load them
using LoadControl() but, the only way this will work is if you never
switch views as part of a post back OR you don't use viewstate.

The reason it loads all of the controls is so that it can re-establish
the state of the objects.



-----Original Message-----
From: DC [mailto:[email protected]]

Posted At: Wednesday, November 28, 2007 10:47 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Avoid execution of "Page_Load" of controls contained in
MultiView Views
Subject: Avoid execution of "Page_Load" of controls contained in
MultiView Views

Hi,

the subject says it all. Since visible=false controls will still run
though Page_Load, I was hoping that the MultiView would somehow manage
to avoid a Page_Load of controls in its inactive Views. But of course
it does not.

I guess a safe way to avoid Page_Load is to only add the controls at
runtime into the activated view. Which of course neglects the beauty
of editing the layout if several views in one ascx.

Is there a more elegant way or at least a way to safely jump out of
Page_Load of the control (without checking the state of the parents,
please - since the control is not supposed to work in a View only).

TIA for any hint,

Regards
DC- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Thanks, Dave. I was hoping that I only have to make sure that the
controls which are actually postback targets exist. I am unsure about
how "complete" the control tree must be for postbacks/viewstate to
work. I will try out.

Regards
DC
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top