Hi Geo,
As for dynamic ASP.NET server controls, both Page_Init and Page_Load is the
possible place to create and add them. However, Init is the prefered one
since the Page haven't begun loading viewstate at that time.... So the
general steps for creating dynamic webcontrols and retrieve values from
them in other events are:
1. creating them in Page Init or Load events and add them into page's
control collection/hierarchy...
2. In page's post back events (not init or load events) , read their
properties, since at that time, we can ensure the dynamic controls are
created and have restored their properties from viewstate and the posted
values....
Here is a kb article mentioned create dynamic server controls in asp.net
webform:
#HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET
http://support.microsoft.com/kb/317794/en-us
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Dotnet Gruven" <
[email protected]>
| References: <
[email protected]>
<
[email protected]>
| Subject: Re: Retrieving User's Input from Dynamically added WebControls
| Date: Fri, 20 Jan 2006 11:58:11 -0500
| Lines: 49
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-RFC2646: Format=Flowed; Response
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| Message-ID: <#
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: c-24-128-25-74.hsd1.ma.comcast.net 24.128.25.74
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:372449
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks for your input Ranjan, perhaps I wasn't very clear.
|
| They are server controls, since they are created in code. It would be
much
| easier if I could define them declaratively, however, I don't know before
| the request is made, based upon the Query string and what that points to
in
| the database, what the page should contain.
|
| Having looked into this further, it looks like the page life cycle might
| hold the answer. Perhaps I should create the controls in another page
event
| other than Page_Load??
|
| Basically, I need to know how to create controls dynamically so that I
can
| get the values out on the postback.
|
| TIA,
| geo
|
|
| "Ranjan Sakalley" <construqt.yahoo.com> wrote in message
| | >I think you should make these controls as Server side controls ( runat =
| >server), define them in the code behind file, and then use them.
| >
| > Here is a weak pointer
http://www.asp101.com/lessons/htmlcontrols.asp
| >
| > HTH,
| > r.
| >
| >
| >
| >> I've built a WebForm with a Table added dynamically in Page_Load when
| >> IsPostBack is false. The table includes a couple of TextBoxes,
| >> RadioButtonLists and CheckboxLists.
| >>
| >> On postback, those controls are not present nor their valves in
| >> Request.Form.AllKeys.
| >>
| >> What is the strategy to use in order to accomplish list? (Pointers to
| >> tech articles would be very helpful, as I'm not even sure where to
| >> start)
| >>
| >> TIA,
| >>
| >> geo
| >>
| >
| >
|
|
|