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

Dynamically addidng a user control...

P: n/a
I know that in order to receive events from dynamically added controls, you need to recreate the control with each postback, and then re-attach the event handler.

This is thge first time I am trying to dynamically add a user control (ascx), which is a composite control of a couple of drop down controls, one for month and one for year.

I use the LoadControl statement to dynamically add the usercontrol. I then give the usercontrol an ID and attach an event handler, but the event handler never fires, even though I re reload the usercontrol and re-attach the event handler.

How can I process the events of the contained ddl controls within the ascx control?

I have no problem processing the events of the ascx when the usercontrol is drawn on the web form at design time.

Thanks in advance for any comments.

Here's the relevant code:

Protected WithEvents PeriodSelector As sKPIPeriodSelector

Dim Path As String = "../UIObjects/SKPIPeriodSelector.ascx"
PeriodSelector = CType(LoadControl(Path), sKPIPeriodSelector)
PeriodSelector.ID = "PeriodSelector"

AddHandler PeriodSelector.RPTChange, AddressOf PeriodSelector_Change

Private Sub PeriodSelector_Change()
RefreshDisplay() 'IT NEVER COMES IN THIS SUB!!!
End Sub

Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.