ASP.NET - the onclick attribute added to the Button page cannot determine the source of the postback

I just added JavaScript to the onclick Button in ASP.NET to disable the button (so the user doesn't submit the form twice).

When I click this button, the page returns messages in order, but the control event handler does not work - ASP.NET seems to be unable to determine which control sent the page back.

I am a little puzzled by this unexpected behavior. Can someone explain this and suggest an alternative way to do this?

+3
source share
2 answers

Try the following:

<asp:Button ID="Button1" UseSubmitBehavior="false" 
     OnClientClick="javascript:document.getElementById('Button1').disabled = true;    __doPostBack('__Page', '');" 
     onclick="Button1_Click" runat="server" Text="Button" />

It will take place without additional verification of the request.

, onclick: _doPostBack ('_ Page', 'YOURBUTTONNAME') .

+2

, ​​, .

- , .

, .style.display = "none" onclientclick , . , , .

<asp:Button ID="Button1" OnClientClick="javascript:this.style.display = 'none'" 
 onclick="Button1_Click" runat="server" Text="Button" />
+3

Source: https://habr.com/ru/post/1787794/


All Articles