473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

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
Nov 18 '05 #1
3 3630
Ben
Why aren't you using a datagrid?

"PABruceFan" <bb*******@yahoo.com> wrote in message
news:fb*************************@posting.google.co 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


Nov 18 '05 #2
DataGrid, DataList, Repeater.

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

"PABruceFan" <bb*******@yahoo.com> wrote in message
news:fb*************************@posting.google.co 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

Nov 18 '05 #3
"PABruceFan" <bb*******@yahoo.com> wrote in message
news:fb*************************@posting.google.co 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
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Williamson | last post by:
When a ASPX page is created with dynamic controls based on what the user is doing the programmer must recreate the dynamic controls again on PostBack in the Page_Load so that it's events are wired...
3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
1
by: russ | last post by:
Hi all, Here's a problem I'm having with a dynamic table. Following the guidelines here (http://www.codeproject.com/aspnet/dynamiccontrols.asp), which make perfect sense. The problem is that...
0
by: Prodip K Saha | last post by:
Many Programmers stay away from loading User Control dynamically on the Web Form because of the complexity associated with it's state management and event handling. It is easy to load a User...
13
by: rn5a | last post by:
In a shopping cart app, suppose a user has placed 5 orders, I want to show him 5 LinkButtons (one for each order) so that when he clicks the first LinkButton, he would be shown the details of his...
5
by: lucius | last post by:
Can someone provide a sample of how to add a new CheckBox control to an ASP.NET page, dynamically completely in code-behind? I am having a problem understanding which event should handle the...
0
by: Scott Roberts | last post by:
I always thought that the viewstate "keys" included the control ID. As long as the control IDs were unique, there shouldn't be any conflicts. Well, it appears that that may not be the case with...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
6
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs , i.e. except of fist dropdown list no dropdownlist...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.