如何防止页面回发Button_Click事件发生 [英] How to prevent a page Post Back on Button_Click event occurs

查看:71
本文介绍了如何防止页面回发Button_Click事件发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要获得一个解决方案,以防止发布按钮点击事件时页面回发。但我仍然需要继续使用Button_Click事件,只需要阻止回发。



我已经尝试使用OnClientClick =return false;这完全阻止了调用Button_Click事件。



我非常感谢你的帮助。

Hi,

I need to get a solution for how to prevent a page post back on a button click event occurs. But I need to still continue with the Button_Click event and only need to prevent the post back.

I already tried with OnClientClick="return false;" this completely preventing to call the Button_Click event.

Your help will he highly appreciated.

推荐答案

你不能。而且你需要了解网络是如何工作的,以了解为什么你不能。 C#在服务器上运行,并且运行客户端必须回发。



现在,您可以做的是更改按钮单击以调用JavaScript,然后将您的代码作为Web服务调用。查看jQuery的
You can't. And you need to understand how the web works to understand why you can't. C# runs on the server and for it to run the client has to postback.

Now, what you can do is change the button click to call JavaScript that then calls your code as a webservice. Look at jQuery's


.ajax()方法。
.ajax() method.


使用更新面板以避免整页加载...
Use Update panel for avoiding full page loading...


这篇关于如何防止页面回发Button_Click事件发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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