有什么办法来阻止一个asp:在C#中按钮的onClick事件在JavaScript中的OnClientClick事件? [英] Is there any way to block an asp:Button's OnClick event in C# from the OnClientClick event in javascript?

查看:202
本文介绍了有什么办法来阻止一个asp:在C#中按钮的onClick事件在JavaScript中的OnClientClick事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp:按钮在我的网页,它调用到一个Javascript功能和code隐藏方法。后者要求一个导航到另一个页面。在JavaScript函数中,我检查的条件。如果这个条件不满足,我想中止导航,即不调用OnClick方法。这可能吗?

 < ASP:按钮的OnClick =Button_ClickID =措施1的OnClientClick =SaveValues​​()文本=措施1的CssClass =specialButton=服务器/ >


解决方案

是的,就返回

 < ASP:按钮的OnClick =Button_ClickID =措施1
    的OnClientClick =返回SaveValues​​();文本=措施1的CssClass =specialButton=服务器/>

假设 SaveValues​​ 也将返回一个布尔值的条件是否得到满足。

I have an asp:Button on my webpage, and it calls into a Javascript function and a code-behind method. The latter calls for a navigate to another page. In the Javascript function, I'm checking for a condition. If this condition is not met, I want to abort the navigation, i.e. not call the OnClick method. Is this possible?

<asp:Button OnClick="Button_Click" ID="Action1" OnClientClick="SaveValues()" Text="Action1" CssClass="specialButton" runat="server" />

解决方案

Yes, just return false:

<asp:Button OnClick="Button_Click" ID="Action1" 
    OnClientClick="return SaveValues();" Text="Action1" CssClass="specialButton" runat="server" />

Assuming that SaveValues will also return a boolean whether or not the condition was met.

这篇关于有什么办法来阻止一个asp:在C#中按钮的onClick事件在JavaScript中的OnClientClick事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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