Hi!
Is there any consensus as to the best way to handle dynamic button clicks? The buttons are being created dynamically and conditionally placed, depending on business logic.
Our problem is that on clicking such a button, the postback calls the Page_Load but not the Button_OnClick. I notice that if I use a static button on the page, this problem does not occur, but that thwarts our business logic.
What we're trying to achieve is to add an "Edit" button. When clicked, it changes the layout of the page, and no longer shows this "Edit" button. (Instead, "Save", "Discard", etc...).
We're trying to avoid making the buttons static, with visibility controlled by logic, as that would be such a limiting factor. e.g. we may want a dynamic array of buttons where the size of the array is unknown at design time. How would their click events be caught?
Any ideas?!
Stewart
Button EditButton;
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
setupMostOfPage(); // based on business logic
}
if (!editMode) {
// creates and places the button in placeholder if not in editMode
setupEditButton();
}
}
EditButton_OnClick(object sender, EventArgs e) {
// doesn't go here even when business logic creates button
editMode = !editMode;
setupMostOfPage(); // now sets it up based on editMode
}