I'm working on a Webpart for SharePoint with ASP.NET
On every click my page will be reloaded and I add a List of Checkboxes with different ID's in two tables and a event to handle the CheckedChanged Event (all the same).
In Addition the autopostback is set to true.
When I run and click my first checkbox every thinks work fine. By clicking the next checkbox in the same table, I get in my eventReceiver 2! Events - first, the right one and after that the checkbox was clicked before.
As many boxes I click, as many checkboxes fire their Event (when used before).
Only difference is between the 2 Tables. Here clicking in first table all is ok, clicking in second table all ok... after that each table has the same effect. Click in first table again, I get 2 Events to handle, click in the second one these 2 to handle.
I have no idea what's going wrong.
Here's some code
CheckBox eMailNotifikation = new CheckBox() { TextAlign = TextAlign.Right };
eMailNotifikation.ID = #anCounter + "_" + #anName + "_" + #anothername + "_" + "mail_checkbox";
eMailNotifikation.AutoPostBack = true;
eMailNotifikation.CheckedChanged -= new EventHandler(eMailNotifikation_CheckedChanged);
eMailNotifikation.Checked = #setInitialValue;
//Add Event
eMailNotifikation.CheckedChanged += new EventHandler(eMailNotifikation_CheckedChanged);
cell.Controls.Add(eMailNotifikation);
that's it for creation
here's my receiver:
void eMailNotifikation_CheckedChanged(object sender, EventArgs e) {
CheckBox eMailNotification = (sender as CheckBox);
//Do some... calling a Webservice
eRoomWebservice.DoMyTasl(<params>);
}
the tables are only build with new... and ID.. nothing Special
EDIT:::: I've build the code in easy ASP.NET and there it is working, maybe this is a SharePoint Issue protected void Page_Load(object sender, EventArgs e) { Table test = new Table(); test.ID = "test1";
TableHeaderRow thr = new TableHeaderRow();
TableHeaderCell thc = new TableHeaderCell();
thc.Text = "Checkboxes";
thr.Controls.Add(thc);
test.Controls.Add(thr);
TableRow tr = new TableRow();
for (int i = 0; i < 10; i++)
{
TableCell tc = new TableCell();
CheckBox chb = new CheckBox();
chb.ID = "Some_" + i;
chb.AutoPostBack = true;
chb.CheckedChanged += new EventHandler(TestEH);
tc.Controls.Add(chb);
tr.Controls.Add(tc);
}
test.Controls.Add(tr);
root.Controls.Add(test);
}
void TestEH(object sender, EventArgs e) {
CheckBox chbx = sender as CheckBox;
string text = chbx.ID;
}
i found out wha'ts the Problem on my posted issue.
Content of the attribute ID="" was too Long, after shrinking the IDName it was working again.
Strange but it was the solution, Remember: Watch out how Long Content of the Attribute ID is, there must be a Limit somewhere