CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [RESOLVED] Conflicting event handlers

  1. #1
    Join Date
    Jan 2010

    [RESOLVED] Conflicting event handlers

    My page consists of a table containing both buttons and radiobuttons. Each have a seperate event handler. My problem is as follows: when I click on a button, the button AND the radiobutton event handler are called instead of just the first. When I click on a radiobutton nothing happens. I assume there is a confliction here because two event handlers are used in one method. How do I solve this?

             protected void CreateTblMainSkill()
                 int i = 0;
                // Create a cell with a skill in each row
                foreach(object skill in criterium)
                    btnSkill = new Button();
                    cellSkill = new TableCell();
                    rowSkill = new TableRow();
                    btnSkill.ID = Convert.ToString(criterium[i].ID);
                    btnSkill.Text = Server.HtmlDecode(criterium[i].Skill);
                    // On button click display side table for desired skill
                    btnSkill.Click += new EventHandler(btnSkill_CheckedChanged); // PROBLEM LIES HERE
                    // For every skill add rbtn for each ENumGrade
                    for (int c = 0; c < eNumGradesList.Length; c++)
                        cellRbtn = new TableCell();
                        rbtnSkill = new RadioButton();
                        rbtnSkill.ID = Convert.ToString(criterium[i].ID) + " , " + c;
                        rbtnSkill.Checked = false;
                        rbtnSkill.GroupName = Convert.ToString(criterium[i].Skill);
                        rbtnSkill.CheckedChanged += new EventHandler(rbtnSkill_CheckedChanged); // PROBLEM ALSO LIES HERE
                    // Add the following rows to the stage
    This is what my event handlers look like:

             private void btnSkill_CheckedChanged(object sender, EventArgs e)
                    MessageBox("Test: Button Event handler");
            protected void rbtnSkill_CheckedChanged(object sender, EventArgs e)
                MessageBox("Test: Radiobutton event handler!");

  2. #2
    Join Date
    Nov 2002
    .NET 3.5 VS2008

    Re: Conflicting event handlers

    You will probably have to change your radio buttons to auto postback. By default they do not autopostback. when you click the proper button a postback is done and now it has to handle two events: the click of the radio button (which did not have an immediate effect) and the click of the proper button which caused the postback. So change the AutoPostBack to true for the radio buttons.

  3. #3
    Join Date
    Jan 2010

    Re: Conflicting event handlers

    Thank you very much for the quick reply! It does the trick

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)