Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dynamic Control Creation and ViewState: what is the ASP.Net way?

Reply
Thread Tools

Dynamic Control Creation and ViewState: what is the ASP.Net way?

 
 
PABruceFan
Guest
Posts: n/a
 
      07-30-2004
I am dynamically adding rows to an asp:table as a result of a database
query. The row consists of a label, a textbox and three checkboxes in
that order:

LABEL TEXTBOX CHECKBOX1 CHECKBOX3 CHECKBOX2
name1 email1 checked checked checked
name2 email2 not checked checked checked

I have no problem adding the dynamic controls...

Now, suppose the user clicks on name2/checkbox1 and changes the state
to checked then hits the submit button...I need to write this change
to my database. The problem is that since the controls are dynamic,
there are no page variables that I can access to determine the new
value. To obtain the value I do the following:

string state = Request.Form.Get( "Row2_CheckBox1" );

There is no problem with this and it works fine, it just seems like it
NOT the ASP.NET way of doing things. Is there a better, more ASP.NET
way of doing things?????

TIA-

Barry
 
Reply With Quote
 
 
 
 
Ben
Guest
Posts: n/a
 
      07-30-2004
Why aren't you using a datagrid?

"PABruceFan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> I am dynamically adding rows to an asp:table as a result of a database
> query. The row consists of a label, a textbox and three checkboxes in
> that order:
>
> LABEL TEXTBOX CHECKBOX1 CHECKBOX3 CHECKBOX2
> name1 email1 checked checked checked
> name2 email2 not checked checked checked
>
> I have no problem adding the dynamic controls...
>
> Now, suppose the user clicks on name2/checkbox1 and changes the state
> to checked then hits the submit button...I need to write this change
> to my database. The problem is that since the controls are dynamic,
> there are no page variables that I can access to determine the new
> value. To obtain the value I do the following:
>
> string state = Request.Form.Get( "Row2_CheckBox1" );
>
> There is no problem with this and it works fine, it just seems like it
> NOT the ASP.NET way of doing things. Is there a better, more ASP.NET
> way of doing things?????
>
> TIA-
>
> Barry




 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      07-30-2004
DataGrid, DataList, Repeater.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"PABruceFan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> I am dynamically adding rows to an asp:table as a result of a database
> query. The row consists of a label, a textbox and three checkboxes in
> that order:
>
> LABEL TEXTBOX CHECKBOX1 CHECKBOX3 CHECKBOX2
> name1 email1 checked checked checked
> name2 email2 not checked checked checked
>
> I have no problem adding the dynamic controls...
>
> Now, suppose the user clicks on name2/checkbox1 and changes the state
> to checked then hits the submit button...I need to write this change
> to my database. The problem is that since the controls are dynamic,
> there are no page variables that I can access to determine the new
> value. To obtain the value I do the following:
>
> string state = Request.Form.Get( "Row2_CheckBox1" );
>
> There is no problem with this and it works fine, it just seems like it
> NOT the ASP.NET way of doing things. Is there a better, more ASP.NET
> way of doing things?????
>
> TIA-
>
> Barry



 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      07-31-2004
"PABruceFan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> I am dynamically adding rows to an asp:table as a result of a database
> query. The row consists of a label, a textbox and three checkboxes in
> that order:
>
> LABEL TEXTBOX CHECKBOX1 CHECKBOX3 CHECKBOX2
> name1 email1 checked checked checked
> name2 email2 not checked checked checked
>
> I have no problem adding the dynamic controls...
>
> Now, suppose the user clicks on name2/checkbox1 and changes the state
> to checked then hits the submit button...I need to write this change
> to my database. The problem is that since the controls are dynamic,
> there are no page variables that I can access to determine the new
> value. To obtain the value I do the following:
>
> string state = Request.Form.Get( "Row2_CheckBox1" );
>
> There is no problem with this and it works fine, it just seems like it
> NOT the ASP.NET way of doing things. Is there a better, more ASP.NET
> way of doing things?????


You should be using a DataGrid or such. But if you really have to add the
controls "manually", then you have to add them on every page request, and in
the exact same order. If you do this, then the controls will load their
ViewState as well as the values posted from the form. This will make the new
values available in the Text or Checked properties, and it will allow the
controls to raise events when these values change.
--
John Saunders
johnwsaundersiii at hotmail


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic creation of a user control with a dropdownlist Hugo Flores ASP .Net 1 09-06-2006 02:33 AM
Dynamic control creation design issue =?Utf-8?B?UGF1bA==?= ASP .Net 0 02-21-2006 07:45 AM
How to (batch) set EXIF date taken and IPTC creation date and creation time for photos with filenames YYMMDDHHMMSS#.jpg? guercheLE@gmail.com Digital Photography 1 10-04-2005 07:15 PM
Dynamic Control Creation and ViewState: what is the ASP.Net way? PABruceFan ASP .Net Web Controls 3 07-31-2004 06:43 PM
Dynamic Control Creation w/Events? Jeff Voigt ASP .Net 1 07-08-2003 07:08 PM



Advertisments