Reputation: 4520
I have an UpdatePanel control in my ASP.NET application (actually several, but that's not the concern).
<asp:UpdatePanel ID="UpdatePanelDetail" runat="server" UpdateMode="Conditional">
<ContentTemplate>
...More code here
Inside the panel, there exists an asp:Table
object:
<asp:Table ID="tblGIFs" runat="server"></asp:table>
This table gets programmatically generated via some code from codebehind:
TableRow htr = new TableRow();
TableCell htc = new TableCell();
...<snip>
tblGIFs.Rows.Add(htr)
And that's all fine, except in one of the cells I am trying to add a button (with an image):
htc3.Text = "<input ID=\""+ii.Value+"\" OnClick = \"btnGIFSearch(this)\" type=\"image\" value=\"/Image/Fiu.png\" />";
When this image is clicked, the onclick
fires fine, but the entire UpdatePanel
gets refreshed (and consequentually, the asp:Table
disappears).
If I use a type="button"
, it works completely fine and there's no issue with refreshing/losing the content in the table.
I've run the page with breakpoints on every location that I'm touching the table from codebehind to no avail, there's really nothing more that I can see that could cause the UpdatePanel
to be cleared programtically.
Anyone seen similar behavior with these tags/controls and any idea of a resolution? A workaround is obviously using type=button
and just styling the button, but I rather not do that if I can get type=image
behaving correctly.
Upvotes: 1
Views: 1024
Reputation: 14619
An input type "image" is like a submit button. It's submitting the form, because that's what they do. If your code-behind is not rebuilding the table in the case of a postback that you don't expect, the table won't be rebuilt, and hence disappear (keep in mind whenever you build controls dynamically, you must do so every request). If you don't want the button to postback, have your OnClick handler return false to cancel the post. If you DO want the button to postback, then you have a different problem, probably related to using dynamic controls incorrectly.
Upvotes: 9