Events don't fire for dynamically loaded control when loaded by an event procedure

R

RND

If a child control is loaded dynamically during a host page event handler,
the events of that control do not appear to be detected by the host page. If
that same control is loaded in the same way during page_load or page_init,
then the child's events are detectable. Is there any way to change the
behavior?

Example: I have a single host page that loads many different simple UI
controls one at a time for editing various information. Doing it this way
makes the pages small for round tripping. For a smooth design, the child
control raises an event saying it is done editing and signalling what the
next required editing control is. So the host page handles this event as:

Private Sub m_PageUserControl_OnDone() Handles
m_PageUserControl.OnDone
Try
ContentPane.Controls.Clear()
m_PageUserControl =
DirectCast(LoadControl(m_Listings.SearchControlUrl),
ucBasicListingUserControl)
m_PageUserControl.objListings = m_Listings
m_PageUserControl.LoadData()
ContentPane.Controls.Add(m_PageUserControl)
lblCurrentControl.Text = m_Listings.SearchControlUrl
Catch ex As Exception
LogException(ex)
End Try
End Sub

The host page saves what the currently loaded editing control is and loads
it automatically during routine postbacks. When it receives this event, it
switches which control is loaded. The problem is that a routine postback is
necessary before any events can be detected coming from the child control.
Even routine events within the child control like a linkbutton click or
something don't fire until the first wasted postback happens. In fact the
following wasteful addtion makes it work right. Every time the control is
loaded as above, it forces a gratuitous postback (two round trips for the
request).

Page.RegisterStartupScript("gratisPostBack", "<script
language=JavaScript>__doPostBack('" & ContentPane.ClientID &
"','')</script>")

Is there any way around this? What can I do to make those child control
events work as expected? So what if the control was loaded in event_handler
instead of in page_load?

Thanks
 
G

Guest

Hi RND,

Does my reply make sense to you? Is your problem resolved?

If you still have any concern, please feel free to feedback, I will help
you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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

Top