Retrieving User's Input from Dynamically added WebControls

D

Dotnet Gruven

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
 
D

Dotnet Gruven

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
 
S

Steven Cheng[MSFT]

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
| >>
| >
| >
|
|
|
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top