user control questions

Apr 9 2005 4:08 PM
Hi, I am adding multiple user controls to a web form dynamically depending on some input criteria such that if I read 7 records from the database then I add the user control 7 times to my aspx page. My problem starts with the following: Everytime I reload my page all the controls disappear. I read about this on other forums so I wanted to add all the controls to an arraylist and then add the arraylist to the aspx page's viewstate. When I do that it asks me to implement the serializable attribute but even when I implement the serializable attribute for the web control and the web form, it still bombs out giving me the same error about implementing the serializable attribute. Could somebody please help on this. In my user control I add a table with the tablecells containing a checkbox, a label and a button server controls (with runat=server) and in my aspx page where I add the user control to the placeholder server control, I add the button.click += new System.EventArgs(this.Button_Click) for each button. That means that if I have to add the user control 6 times to my aspx page, each time that the button control is added, this button.click event handler will also be added. My problem is that even though while running any of these user control created button clicks cause a postback and run the web form page_load method, none of them run to the button_click method.Could somebody please suggest me what I should do???? Thanks in advance, Sumeet

Answers (2)