473,387 Members | 1,572 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,387 software developers and data experts.

Dynamic controls losing values

Raj
Hi there,

I am trying to get this work but I can't figure a solution. I have a
table on a web page (.aspx) and creating the table contents
dynamically. I have two cells for each row of table. First cell is a
label field, and second is a radiobuttonlist. Table looks some thing
like

Your favorite color? *)Red *)Blue *)Green
Age? *)20 *)30 *)40

Here comes the problem. In the submit button, I am trying to read the
selection as follows:

RadioButtonList rbl;
TableCell tc;
string sText;
int nTotal = tblStats.Rows.Count;
for (int i = 0; i < nTotal; i++)
{
tc = tblStats.Rows[i].Cells[1];
rbl = (RadioButtonList)tc.Controls[0];
sText = rbl.SelectedItem.Value;
}
The above code will always return the first selection (In the above
example: Red, 20 etc) Even if you select Blue, 40 etc. Actually that's
what the default selections were when page loads.
I have googled it but couldn't find what I was looking for. I will
truly appreciate your input.

Thank you,

Raj

Oct 31 '06 #1
3 1559
You have to re-create dynamically created controls on every postback.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Raj" <an************@yahoo.comwrote in message
news:11**********************@e64g2000cwd.googlegr oups.com...
Hi there,

I am trying to get this work but I can't figure a solution. I have a
table on a web page (.aspx) and creating the table contents
dynamically. I have two cells for each row of table. First cell is a
label field, and second is a radiobuttonlist. Table looks some thing
like

Your favorite color? *)Red *)Blue *)Green
Age? *)20 *)30 *)40

Here comes the problem. In the submit button, I am trying to read the
selection as follows:

RadioButtonList rbl;
TableCell tc;
string sText;
int nTotal = tblStats.Rows.Count;
for (int i = 0; i < nTotal; i++)
{
tc = tblStats.Rows[i].Cells[1];
rbl = (RadioButtonList)tc.Controls[0];
sText = rbl.SelectedItem.Value;
}
The above code will always return the first selection (In the above
example: Red, 20 etc) Even if you select Blue, 40 etc. Actually that's
what the default selections were when page loads.
I have googled it but couldn't find what I was looking for. I will
truly appreciate your input.

Thank you,

Raj

Oct 31 '06 #2
Raj
Eliyahu,

I am doing that. It is just that it is not able to read the values
back. To keep it simple, I am not changing selections either. I just
want the same values that were loaded. Somehow it can't read. It will
always give the first item in radiobuttonlist even though it is not
selected.

Thanks,

Raj

Eliyahu Goldin wrote:
You have to re-create dynamically created controls on every postback.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Raj" <an************@yahoo.comwrote in message
news:11**********************@e64g2000cwd.googlegr oups.com...
Hi there,

I am trying to get this work but I can't figure a solution. I have a
table on a web page (.aspx) and creating the table contents
dynamically. I have two cells for each row of table. First cell is a
label field, and second is a radiobuttonlist. Table looks some thing
like

Your favorite color? *)Red *)Blue *)Green
Age? *)20 *)30 *)40

Here comes the problem. In the submit button, I am trying to read the
selection as follows:

RadioButtonList rbl;
TableCell tc;
string sText;
int nTotal = tblStats.Rows.Count;
for (int i = 0; i < nTotal; i++)
{
tc = tblStats.Rows[i].Cells[1];
rbl = (RadioButtonList)tc.Controls[0];
sText = rbl.SelectedItem.Value;
}
The above code will always return the first selection (In the above
example: Red, 20 etc) Even if you select Blue, 40 etc. Actually that's
what the default selections were when page loads.
I have googled it but couldn't find what I was looking for. I will
truly appreciate your input.

Thank you,

Raj
Oct 31 '06 #3
Raj
I figured why that was happening but I still can't explain why.
Anyways, I was populating RadioButtonList with values from a global
file and that was causing it. Now I am reading the value into a local
variable and using it and every thing works.

Thanks for your time,

Raj

Raj wrote:
Eliyahu,

I am doing that. It is just that it is not able to read the values
back. To keep it simple, I am not changing selections either. I just
want the same values that were loaded. Somehow it can't read. It will
always give the first item in radiobuttonlist even though it is not
selected.

Thanks,

Raj

Eliyahu Goldin wrote:
You have to re-create dynamically created controls on every postback.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Raj" <an************@yahoo.comwrote in message
news:11**********************@e64g2000cwd.googlegr oups.com...
Hi there,
>
I am trying to get this work but I can't figure a solution. I have a
table on a web page (.aspx) and creating the table contents
dynamically. I have two cells for each row of table. First cell is a
label field, and second is a radiobuttonlist. Table looks some thing
like
>
Your favorite color? *)Red *)Blue *)Green
Age? *)20 *)30 *)40
>
Here comes the problem. In the submit button, I am trying to read the
selection as follows:
>
RadioButtonList rbl;
TableCell tc;
string sText;
int nTotal = tblStats.Rows.Count;
for (int i = 0; i < nTotal; i++)
{
tc = tblStats.Rows[i].Cells[1];
rbl = (RadioButtonList)tc.Controls[0];
sText = rbl.SelectedItem.Value;
}
The above code will always return the first selection (In the above
example: Red, 20 etc) Even if you select Blue, 40 etc. Actually that's
what the default selections were when page loads.
I have googled it but couldn't find what I was looking for. I will
truly appreciate your input.
>
Thank you,
>
Raj
>
Oct 31 '06 #4

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

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
0
by: K B | last post by:
PLEASE be patient and read this. I believe I've actually reached the end of the Web trying to find the answer! I have an aspx using a MasterPage with a ContentPlaceholder. I have a datatable...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
4
Frinavale
by: Frinavale | last post by:
Introduction Sometimes, when developing web applications, we need to be able to dynamically load controls based on user selections. The following article describes a simple scenario where TextBox...
2
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
4
by: =?Utf-8?B?RHlsYW5TbWl0aA==?= | last post by:
I have a WebForm where I'm dynamically creating some controls and I'm having difficulty understanding how the state is being persisted and how to work with it. I've created a simplified example...
5
by: Hans Kesting | last post by:
Hi, Is there good information about the asp.net page lifecycle in combination with dynamically loaded controls? Or on "how to build dynamic controls"? I keep hitting problems where values are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.