点击按钮后,ASP.NET页面禁用刷新 [英] Disable page refresh after button click ASP.NET

查看:165
本文介绍了点击按钮后,ASP.NET页面禁用刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp按钮,看起来像这样:

I have an asp button that looks like this:

Default.aspx的

Default.aspx

<asp:button id="button1" runat="server" Text="clickme" onclick="function" />

Default.aspx.cs

Default.aspx.cs

protected void function(object sender EventArgs e)
{
    // Do some calculation
}

然而,每当我preSS按钮,整个页面得到刷新。我已经看过这个网站,发现很多解决方案,但没有人真的适合我的项目。下面是一些建议的解决方案的:

However, whenever I press the button, the entire page gets refreshed. I have looked on this site and found many solutions, but none of them really works for my project. Here are some of the suggested solutions:


  1. 设置的onclick =返回false; //但我怎么跑在$ C $函数C-后面?

  2. 在Page_Load中使用!的IsPostBack //,但是网页仍然完全刷新。我不想的Page_Load在所有被调用。

  3. 禁用AutoEventWireup。 //使这个真的还是假的不会有所作为。

没有任何人有一个解决的办法,或者是不是真的不可能?

Does anyone have a solution to this, or is it really impossible?

推荐答案

我会放置一个更新面板内的控制。
要做到这一点,您还需要它上面的脚本管理器,所以像这样的:

I would place the control inside of an Update panel. To do so, you would also need a script manager above it, so something like this:

 <asp:ScriptManager runat="server" ID="sm">
 </asp:ScriptManager>
 <asp:updatepanel runat="server">
 <ContentTemplate>
 <asp:button id="button1" runat="server" Text="clickme" onclick="function" />
 </ContentTemplate>
 </asp:updatepanel>

如果更新面板内部控制做了回传,只会重新加载页面的部分upate面板内部。的这里是一个链接,你会发现从MSDN网站是有用的。

if a control inside the update panel does a postback, it will only reload the part of the page inside of the upate panel.Here is a link you may find useful from the MSDN site.

这篇关于点击按钮后,ASP.NET页面禁用刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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