By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,561 Members | 3,113 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,561 IT Pros & Developers. It's quick & easy.

Dynamically Loaded User Control Event Wiring

P: n/a
I have a page that can load a number of different user controls. Each of
these user controls inherits from a common base class and the controls are
loaded based on application state, status, etc and the specific type of
control frequently changes. I have a common event in the base class that
each child user control inherits from and that the page wires up and uses to
get status from the child user control. I hope all pretty simple and not too
far out there....

I am loading and wiring the control in the Page_Load event or during a
secondary event in reponse to a button click on the page (in the page
class). The user control is added to a place holder control on the page.

This all works fine but somehow I am not receiving the initial invocation on
of the event on the child user control. It does work the second time around.

Bottom line: during which event on a page should I be loading and wiring
events on a dynamically loaded user control?

Any help on this would be appriciated.

-Andy

May 23 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Andrew Robinson" <ne****@nospam.nospamwrote in message
news:eC**************@TK2MSFTNGP02.phx.gbl...
>I have a page that can load a number of different user controls. Each of
these user controls inherits from a common base class and the controls are
loaded based on application state, status, etc and the specific type of
control frequently changes. I have a common event in the base class that
each child user control inherits from and that the page wires up and uses
to get status from the child user control. I hope all pretty simple and not
too far out there....

I am loading and wiring the control in the Page_Load event or during a
secondary event in reponse to a button click on the page (in the page
class). The user control is added to a place holder control on the page.

This all works fine but somehow I am not receiving the initial invocation
on of the event on the child user control. It does work the second time
around.

Bottom line: during which event on a page should I be loading and wiring
events on a dynamically loaded user control?
The best place to load controls is in the Page_Init() method, I think.
May 23 '07 #2

P: n/a
if you dynamically add a control, on the next postback and all
subsequent postbacks) you should re-add the control and wireup events in
the oninit event.

-- bruce (sqlwork.com)

Andrew Robinson wrote:
I have a page that can load a number of different user controls. Each of
these user controls inherits from a common base class and the controls
are loaded based on application state, status, etc and the specific type
of control frequently changes. I have a common event in the base class
that each child user control inherits from and that the page wires up
and uses to get status from the child user control. I hope all pretty
simple and not too far out there....

I am loading and wiring the control in the Page_Load event or during a
secondary event in reponse to a button click on the page (in the page
class). The user control is added to a place holder control on the page.

This all works fine but somehow I am not receiving the initial
invocation on of the event on the child user control. It does work the
second time around.

Bottom line: during which event on a page should I be loading and wiring
events on a dynamically loaded user control?

Any help on this would be appriciated.

-Andy
May 23 '07 #3

P: n/a
Ok, one more piece of missing info: The particular flavor of my dynamic user
control is determined by info that is stored in ViewState on the host page
(which is not loaded until Page_Init). Seems like a chicken and egg issue.

Thanks,
"bruce barker" <no****@nospam.comwrote in message
news:OW**************@TK2MSFTNGP03.phx.gbl...
if you dynamically add a control, on the next postback and all subsequent
postbacks) you should re-add the control and wireup events in the oninit
event.

-- bruce (sqlwork.com)

Andrew Robinson wrote:
>I have a page that can load a number of different user controls. Each of
these user controls inherits from a common base class and the controls
are loaded based on application state, status, etc and the specific type
of control frequently changes. I have a common event in the base class
that each child user control inherits from and that the page wires up and
uses to get status from the child user control. I hope all pretty simple
and not too far out there....

I am loading and wiring the control in the Page_Load event or during a
secondary event in reponse to a button click on the page (in the page
class). The user control is added to a place holder control on the page.

This all works fine but somehow I am not receiving the initial invocation
on of the event on the child user control. It does work the second time
around.

Bottom line: during which event on a page should I be loading and wiring
events on a dynamically loaded user control?

Any help on this would be appriciated.

-Andy
May 23 '07 #4

P: n/a
Hi Andrew,

As for dynamic created control, they need to be added into Page's control
hierarchy(and wireup event handler) in either Page's Init or Load event.
Also, for ViewState, it is loading after Init and Before Load event. Thus,
if you have some dynamic control generation code logic that depend on
variables in ViewState, you need to use Load event instead of Init event.

One way to avoid using viewstate and also use Init for conditional dynamic
control generation is use a hidden field on page to store the certain
variable that control the dynamic control generation. Such hidden field can
be access through Request.Form collection directly in Init event(before
viewstate load).

Anyway, if possible, you can try show us a simplified page that can repro
the problem you met so that we can have a further look into it.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
May 24 '07 #5

P: n/a
Hi Andrew,

Have you got any further idea on this issue or does the suggestion in
previous reply help you a little?
Please feel free to post here if there is anything else we can help.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

May 28 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.