ASP.NET的按钮 - 的OnClientClick ="复位功能()" VS的OnClientClick ="函数()" [英] Asp .NET Button - OnClientClick="return function()" vs OnClientClick="function()"

查看:117
本文介绍了ASP.NET的按钮 - 的OnClientClick ="复位功能()" VS的OnClientClick ="函数()"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个asp.net的用户控件我有一个按钮:

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

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

我写了jQuery的code隐藏在页面内功能的控制(的ValidationSummary)present()。

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?

推荐答案

第一:在客户端运行(的OnClientClick

First : the client side runs (OnClientClick)

然后 - 服务器端。

Then - the server side.

但是

客户端code的可以prevent 的回报通过服务器端的执行真/假。

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 =返回false;

这篇关于ASP.NET的按钮 - 的OnClientClick =&QUOT;复位功能()&QUOT; VS的OnClientClick =&QUOT;函数()&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆