Dynamic EventHandler Firing Every Postback

Discussion in 'ASP .Net Web Controls' started by StanRajan@gmail.com, Sep 13, 2007.

  1. Guest

    I am work which populates a placeholder with controls that are driven
    by the database. For specific radiobuttonlist controls I need to add
    an eventhandler on the selectedindexchanged event. The problem I am
    encountering is that the event is being fired every time any postback
    occurs to the page. Also, I am using the same event handler for all
    the radiobuttonlist's that I need to capture the event for and using
    the sender to get the ID of which control caused the postback.

    The EventHandler used for the SelectedIndexChanged event:

    private void rbl_SelectedIndexChanged(object sender, EventArgs e)
    {
    RadioButtonList rbl = (RadioButtonList) sender;

    for(int r=0; r < rbl.Items.Count; r++)
    {
    if(rbl.Items[r].Selected)
    {
    // DB UPDATE
    }
    }
    }


    The assignment of the event handlers in the OnInit method:

    override protected void OnInit(EventArgs e)
    {
    // DYNAMIC CONTROLS CREATED

    // ASSIGN EVENT HANDLERS
    ((RadioButtonList) this.FindControl("rbl1")).SelectedIndexChanged +=
    new EventHandler(this.rbl_SelectedIndexChanged);
    ((RadioButtonList) this.FindControl("rbl1")).AutoPostBack = true;

    ((RadioButtonList) this.FindControl("rbl2")).SelectedIndexChanged +=
    new EventHandler(this.rbl_SelectedIndexChanged);
    ((RadioButtonList) this.FindControl("rbl2")).AutoPostBack = true;
    }


    Been stuck on this for awhile, any help would be greatly appreciated.

    Thanks,
    Stan
    , Sep 13, 2007
    #1
    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. Jacob

    Dynamic eventhandler

    Jacob, Feb 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,608
    Eugene Jenihov
    Feb 5, 2004
  2. David Lozzi
    Replies:
    3
    Views:
    269
    David Lozzi
    Apr 15, 2005
  3. =?Utf-8?B?SXJ3YW5zeWFo?=
    Replies:
    4
    Views:
    2,434
    =?Utf-8?B?SXJ3YW5zeWFo?=
    Oct 30, 2007
  4. tsarna

    Sort not firing PostBack event using Dynamic Columns

    tsarna, Jun 23, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    180
    tsarna
    Jun 28, 2004
  5. Anthony Williams

    Help: btnEdit.click += new EventHandler(...) not firing!

    Anthony Williams, Feb 4, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    329
    Anthony Williams
    Feb 4, 2005
Loading...

Share This Page