I want do disable postback after clicking a
. I\'ve tried to do that by assigning onclick=\"return false\"
, but in the button doe
Put your asp button to inside the Updatepanel like
<asp:UpdatePanel ID="updPnl" runat="server" UpdateMode="Conditional" RenderMode="Block">
<ContentTemplate>
<asp:Button ID="btnID" runat="server" OnClick="btn_Click" />
</ContentTemplate>
</asp:UpdatePanel>
Hope this is helpfull
It worked for me like this:
In <body>
:
function myfunction() {
return false;
}
and in <head>
:
<asp:ImageButton ID="ImageButton1" runat="server" Height="52px" Width="58px" OnClientClick="myfunction(); return false;"/>
Seeing as none of these answers helped me. I found a solution. Instead of using the ASP.NET button <asp:Button>
, you should use the HTML button. It worked perfectly and looks exactly like the ASP.NET button. To get the HTML button to submit on server side, you use the attribute onserverclick
.
<input id="btnState" class="AddButtons" runat="server" type="button" value="Add State" onclick="swap('one', 'two');" />
For my code, I was using JS to do something on the server side. The <asp:Button>
would not stop doing a post back but as I said, the HTML button fixed my problem. Please mark as answer or vote up if this helped you out.
by using UseSubmitBehavior="false" you can disable postbacks of onclick
onClientClick="return false"
That should do it! Onclick
will refer to an ASP.net function, onClientClick
will render as OnClick
on the control in HTML.
I could fix that using an UpdatePanel which includes the implicated controls/elements.