retrieving values from dynamically created controls

Discussion in 'ASP .Net Building Controls' started by Jacob, Oct 11, 2003.

  1. Jacob

    Jacob Guest

    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
    ------------------------------------------------
    Jacob, Oct 11, 2003
    #1
    1. Advertising

  2. "Jacob" <> wrote in message
    news:...
    > 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?
    --
    John Saunders
    Internet Engineer
    John Saunders, Oct 11, 2003
    #2
    1. Advertising

  3. Jacob

    Jacob Guest

    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?

    "John Saunders" <john.saunders at surfcontrol.com> wrote in message news:<>...
    > "Jacob" <> wrote in message
    > news:...
    > > 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?
    Jacob, Oct 11, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bryan Donaldson
    Replies:
    0
    Views:
    416
    Bryan Donaldson
    Nov 24, 2003
  2. Nathan Sokalski

    Retrieving values from dynamically added controls

    Nathan Sokalski, Sep 9, 2007, in forum: ASP .Net
    Replies:
    7
    Views:
    1,233
    Scott Roberts
    Nov 20, 2007
  3. msimmons
    Replies:
    0
    Views:
    452
    msimmons
    Jul 16, 2009
  4. Nathan Sokalski

    Retrieving values from dynamically added controls

    Nathan Sokalski, Sep 9, 2007, in forum: ASP .Net Building Controls
    Replies:
    6
    Views:
    939
    Beatrix
    Nov 20, 2007
  5. Nathan Sokalski

    Retrieving values from dynamically added controls

    Nathan Sokalski, Sep 9, 2007, in forum: ASP .Net Web Controls
    Replies:
    7
    Views:
    232
    Scott Roberts
    Nov 20, 2007
Loading...

Share This Page