Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
569 views
Welcome To Ask or Share your Answers For Others

1 Answer

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;"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...