-
January 21st, 2010, 06:44 AM
#1
[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?
Code:
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);
cellSkill.Controls.Add(btnSkill);
rowSkill.Controls.Add(cellSkill);
// 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);
cellRbtn.Controls.Add(rbtnSkill);
rowSkill.Controls.Add(cellRbtn);
rbtnSkill.CheckedChanged += new EventHandler(rbtnSkill_CheckedChanged); // PROBLEM ALSO LIES HERE
}
// Add the following rows to the stage
tblMain.Rows.Add(rowSkill);
i++;
}
}
This is what my event handlers look like:
Code:
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!");
}
-
January 21st, 2010, 06:52 AM
#2
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.
-
January 21st, 2010, 07:13 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|