views:

238

answers:

0

I've written my first UserControl in ASP.Net. It is a user editable ListBox. It contains a ListBox, a HiddenField, a TextBox, and three Buttons (add, remove, and save). Add and remove perform javascript edit of the ListBox and stores the changes in the HiddenField. The save button posts back to the server, causing the HiddenField ValueChanged event to fire. The server then parses the HiddenField ListBox changes and applies them. The control was tested and found to be working properly.

The next step was to use multiple instances of this control on a single page. I created a CompositeControl with containing two instances of the above control, a ListBox, and a Button. I then noticed that the above control's HiddenField ValueChanged event is no longer firing. My research shown me that each instance of the above control required unique Id's and names. So I set the Id's of the controls to a Guid value, but my events still don't fire. More research has shown that the control event's fire during a post back and that the event is fired using the control Id. Applying breakpoints throughout my code has given me insight that the control is recreated each time the page loads, thus changing the control Id. How does ASP.NET know how to fire the event if

A) the control id is changed on each page load B) allow multiple instances of the same control if unique id's are required?