dynamic loading - click event won't fire

C

CalSun

Hi all,
I have a login control. As I add this control at design time, the control
login_button_Click event got called.
However, it doesn't do the same as I add this control dynamically.

Here is how I load the ctrl dynamically

Dim loginctrl As Control

loginctrl = LoadControl("login.ascx")

BodyPage.Controls.Add(loginctrl)

(bodypage is the id of a placeholder)

thank you all for helping.

--calsun
 
T

Teemu Keiski

Hi,

do you do the adding in Page_Load? That's where it should happen for dynamic
controls. See following page/control lifecycle for an explanation.

1. Instantiate
2. Initialize
3. TrackViewState
4. LoadViewState (postback)
5. Load postback data (postback, IPostBackDatahandler.LoadPostdata)
6. Load
7. Load postback data for dynamical controls added on Page_Load (postback)
8. Raise Changed Events (postback,
IPostBackDatahandler.RaisePostDataChanged)
9. Raise postback event (postback, IPostBackEventHandler.RaisePostBackEvent)
10.PreRender
11. SaveViewState
12. Render
13. Unload
14. Dispose

As you see, raising events happens right after Page_Load and it happens by
the Page (so control playing catchup in dynamic control scenario won't help
with it) so controls raising events must be in Controls collection at the
Page_Load at the latest.
 

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,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top