Re: Dynamic WebControl events...

Mark Brackett <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.web
Message-ID <[email protected]>
I believe that the "catching up" of the lifecycle is for the *control's*
lifecycle - not the Page. Since it is the Page lifecycle that populates
viewstate and the IPostBackHandler data, missing the Page lifecycle does
not get those actions done. However, all of the control lifecycle events
(Init, Load, etc.) would be fired.

As a confirmation of this, I moved the checkbox creation to
Page_PreRender, and it does *not* maintain viewstate or trigger the
event handler - both of which would have already passed in the Page
lifecycle.

--MB

-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
[mailto:[email protected]] On Behalf Of Efran Cobisi
Sent: Wednesday, February 14, 2007 11:00 AM
To: [email protected]
Subject: Re: [DOTNET-WEB] Dynamic WebControl events...

This is incorrect.
Control's life cycle begins after they have been added to their parent
controls; so, even if you add a Control to another Controls collection
in the Page PreRender event, it will still fire its postback events...
As Stacey pointed out, setting the AutoPostback property to true will
solve this problem.

HTH,

Efran Cobisi
http://www.cobisi.com

Paul van Brenk wrote:
> You should create the checkbox in the Init event... on the postback
the
> checkbox is created after the events are handled (ie. Too late).
>
> Paul
>
> -----Original Message-----
> From: Discussion of building .NET applications targeted for the Web
> [mailto:[email protected]] On Behalf Of Mike Andrews
> Sent: Wednesday, February 14, 2007 16:51
> To: [email protected]
> Subject: [DOTNET-WEB] Dynamic WebControl events...
>
> Guys,
>
> I'm having problems getting an aspx page to process an event for a
> control,
> namely a checkbox, that was dynamically created and added to the form.
> Any suggestions?
>
> Thanks,
> Mike
>
> Here's a sample of the code:
>
>     protected void Page_Load(object sender, EventArgs e) {
>
>         CheckBox cb = new CheckBox();
>         cb.ID = "test";
>         cb.Text = "Click Here!";
>         cb.CheckedChanged += new EventHandler(cb_CheckedChanged);
>         this.Form.Controls.Add(cb);
>
>     }
>
>     void cb_CheckedChanged(object sender, EventArgs e) {
>         //Do something here
>     }
>
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com
>
> View archives and manage your subscription(s) at
http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.