简体   繁体   English

aspx按钮防止回发onclick(C#)

[英]aspx button prevent postback onclick (c#)

The code below shows some HTML with a <asp:Button> element. 下面的代码显示了一些带有<asp:Button>元素的HTML。

<asp:Button ID="CalculateG481" runat="server" Text="Calculate" OnClick="CalculateG481_Click" />

This calls the function CalculateG481_Click but then posts back. 这将调用函数CalculateG481_Click ,然后回发。

I have tried using OnClientClick="return false" but this simply prevents the button from executing CalculateG481_Click 我尝试使用OnClientClick="return false"但这只是阻止了按钮执行CalculateG481_Click

I have also tried OnClick="CalculateG481_Click; return false;" 我还尝试了OnClick="CalculateG481_Click; return false;" as well to no avail. 也无济于事。

EDIT: CalculateG481_Click is a C# Codebehind function. 编辑: CalculateG481_Click是一个C#Codebehind函数。

The way you are doing is really strange - you cannot call Server-Side Button Event from Client-Side JavaScript . 您的操作方式确实很奇怪- 您无法从客户端JavaScript调用服务器端按钮事件

You can either use regular input html tag with pure Client-Side calculation or Server Button Control with Ajax based on your requirement. 您可以根据需要将常规输入html标记用于纯客户端计算,也可以将Server Button Control与Ajax结合使用

Easiest way is to use Ajax UpdatePanel , and place everything inside it. 最简单的方法是使用Ajax UpdatePanel并将所有内容放入其中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM