Groups | Blog | Home
all groups > asp.net building controls > july 2005 >

asp.net building controls : dynamic loading - click event won't fire


CalSun
7/8/2005 11:51:15 AM
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

Teemu Keiski
7/12/2005 12:00:00 AM
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.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

CalSun
7/20/2005 11:24:20 AM
Thanks a lot


[quoted text, click to view]

AddThis Social Bookmark Button