retrieving values from dynamically created controls

J

Jacob

Hi,

Someone please clear this for me!

I display a bunch of button controls on a page dynamically, adding them to a
placeholder control in my .aspx. I have a button with a on_click event that
is suppose to grab the values from those dynamic controls.

I create the controls like so:

RadioButton _rb = null;

for(int x = 0; x <= 5; x++)
{
_rb = new RadioButton();

_rb.GroupName = "group1";
_rb.Text = "label#" + x;



ph.Controls.Add(_rb);
ph.Controls.Add(new LiteralControl("<br>"));
}

And the button event that is too grab the values from the dynamically
created controls:

public void btn_Click(object sender, EventArgs e)
{
Response.Write("<br>Button Clicked!<br>");

RadioButton _rb = null;

for(int x = 0; x <= 5; x++)
{
_rb = new RadioButton();
_rb.GroupName = "group1";
_rb.Text = "label#" + x;
Response.Write("<br>Label#" + x + "is checked=" + _rb.Checked + "<br>");



}

}


What is the best practise for this?


------------------------------------------------
..Net Resources
http://www.asp.net
http://www.aspalliance.com
http://www.csharpfriends.com
http://www.dotnetjunkies.com
http://www.aspadvice.com
http://www.msdn.com
http://weblogs.asp.net
------------------------------------------------
 
J

John Saunders

Jacob said:
Hi,

Someone please clear this for me!

I display a bunch of button controls on a page dynamically, adding them to a
placeholder control in my .aspx. I have a button with a on_click event that
is suppose to grab the values from those dynamic controls.

I create the controls like so:

And are you recreating them upon postback, and are they being recreated in
the same order in which they were originally created?
 
J

Jacob

Yes, I was doing a recreation on postback but that didn't seem to wrk.

Does anyone have an example of this, I am really confused....should I
change the ID of the control so I konw the name of them for sure?
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top