How do I handle "FindControl requires that controls have unique IDs" when i want controlls with the same name?
I'm using jquery/ajax to create a modal window with some text boxes. I then use jquery serialize to post the information in these boxes back to my web forms codebehind
generating code
t.Controls[i].Controls.Add(new TableCell());
t.Controls[i].Controls[2].Controls.Add(new Label { Text = getResXTextAutoInsert(Cache, "valueLable", "EditDiscounts", getLanguage(), "Ver开发者_JS百科di") + " " });
t.Controls[i].Controls[2].Controls.Add(new TextBox() { Text = discount.DiscountAmmount.ToString(), ID = "discAmount"});
t.Controls[i].Controls[2].Controls.Add(new HiddenField() { Value = discount.DiscountId, ID = "discID" });
I expect that when I do a Request["discID"] i should get an comma separated array of integers with the ID's I want, and this is exactly what my debugger show me getting in page_load.
However the web.form gets an exception: Multiple controls with the same ID 'discTypeDrop' were found. FindControl requires that controls have unique IDs.
The only way I can see around this problem is to generate uniqeID's for each input field, instead of storing the ID in the hiddenfield. But I then have to generate some ugly code to loop through the request.form and extract the ID from the keyname, and the value from the value field.
So any suggestion on how to solve this?
You can loop through all the controls and their children recursively using the Control.Controls property and check if each control has the property/setting you are looking for on it.
精彩评论