Author: cykill | Posted on: 4/22/2009 10:11:46 PM | Views : 376

ok, I have a dynamically created web form control.  How can I rewire this so that it doesn't lose the event handler after a postback.
 Below is a snippet of my code.  The problem I have is that the form uses dynamically generated values that's needed for the form to update the correct sql record.  So I can't wire the event handler too early in the life cycle.  Each time the button is clicked, it would update sql and do a postback which will recreate the form.  Any ideas?

protected Panel showForm(string id){
 Button submit = new Button();
submit.ID = id;
button.Click += new EventHandler(addComment);

}

 
protected void addComment(Object sender, EventArgs e){
 Button button = (Button)Sender;
string id = button.ID;
//update sql db with id here.

}

...

Go to the complete details ...