Disable postback at click on a button

后端 未结 10 555
名媛妹妹
名媛妹妹 2021-01-03 20:31

I want do disable postback after clicking a . I\'ve tried to do that by assigning onclick=\"return false\", but in the button doe

相关标签:
10条回答
  • 2021-01-03 21:02

    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

    0 讨论(0)
  • 2021-01-03 21:14

    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;"/>
    
    0 讨论(0)
  • 2021-01-03 21:17

    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.

    0 讨论(0)
  • 2021-01-03 21:17

    by using UseSubmitBehavior="false" you can disable postbacks of onclick

    0 讨论(0)
  • 2021-01-03 21:18
    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.

    0 讨论(0)
  • 2021-01-03 21:23

    I could fix that using an UpdatePanel which includes the implicated controls/elements.

    0 讨论(0)
提交回复
热议问题