OK - so I'm using C# in ASP.net with AJAX (microsoft's AJAX).
on my source page I have the following:
the code behind page draws a lit of items with edit buttons programmatically drawn to the page. Each button has the same CommandName ("edit") with unique CommandArgument values by the unique identifier from the database.Code:<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <table width="300"> <tr> <td><asp:Label ID="mainLabel" runat="server" Text="Label"></asp:Label></td> </tr> </table> </ContentTemplate> </asp:UpdatePanel>
the first time the page loads you can select an 'edit' button for a row. Then it redraws the page and programmatically placed 'save' and 'cancel' buttons on the specifically selected row for editing. But when you click the Save (or cancel) button it does not fire the eventHandler's event for that specific button. But...it does redraw the page, this time with the original Edit buttons and those events fire normally again....
here is the code for the Save button that is drawn after the edit button is clicked:
and here is the code for the edit button:Code:Button saveButton = new Button(); saveButton.CommandName = "Save"; saveButton.Text = saveButton.CommandName; saveButton.CommandArgument = "" + c.getTitleID();//passing this to event handler saveButton.Command += new CommandEventHandler(saveButton_Command); //handler sub.Controls.Add(saveButton);
"sub" is a label that will be the parent control for all of this, which is later drawn to the page.Code:Button editButton = new Button(); editButton.CommandName = "Edit"; editButton.Text = editButton.CommandName; editButton.CommandArgument = ""+c.getTitleID();//passing this to event handler editButton.Command += new CommandEventHandler(editButton_Command); //handler //editButton.CommandArgument = ""+c.getCategoryID(); sub.Controls.Add(editButton);
I can only suspect that it's something to do with the redraw of the page in AJAX but I'm just grasping at straws. I've turned on 'EnableViewState for a bunch of the AJAX and Label controls in the HTML source page - didn't make a difference though...




Reply With Quote