admin管理员组

文章数量:1194328

In an asp user control I have a button:

<asp:Button ID="addButton" runat="server" Text="Add"  OnClientClick="return function()". 

I had written jquery code to hide a control( validationsummary) present in the page inside function().

When I wrote "return function()" it behaved as I expected and the control got hidden. While when I wrote only "function"()" the control got hidden but reappeared. What exactly is the difference between the two?

In an asp.net user control I have a button:

<asp:Button ID="addButton" runat="server" Text="Add"  OnClientClick="return function()". 

I had written jquery code to hide a control( validationsummary) present in the page inside function().

When I wrote "return function()" it behaved as I expected and the control got hidden. While when I wrote only "function"()" the control got hidden but reappeared. What exactly is the difference between the two?

Share Improve this question asked Nov 17, 2013 at 8:45 user2645830user2645830 3621 gold badge6 silver badges22 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 22

First : the client side runs (OnClientClick)

Then - the server side.

But

The client side code can prevent execution of server side by return true/false.

usually we use it for validation , before submitting to server.

Do this and your server side will ( without hacking) never work :

OnClientClick="return false;"

本文标签: cAsp NET ButtonOnClientClickquotreturn function()quot vs OnClientClickquotfunction()quotStack Overflow