加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – ajax中的Updatepanel总是运行page_load事件?

发布时间:2020-12-16 06:32:35 所属栏目:asp.Net 来源:网络整理
导读:我是ajax的新手,并使用visual studio 2005和framework 2.0.一个简单的Ajax示例总是占用页面加载事件以进行按钮单击.没有部署,所有只是在调试模式下运行都会将我带到Page_Load事件.不知道是什么问题?我检查了UpdatePanel1.IsInPartialRendering和ScriptManag
我是ajax的新手,并使用visual studio 2005和framework 2.0.一个简单的Ajax示例总是占用页面加载事件以进行按钮单击.没有部署,所有只是在调试模式下运行都会将我带到Page_Load事件.不知道是什么问题?我检查了UpdatePanel1.IsInPartialRendering和ScriptManager1.IsInAsyncPostBack的值,该值为false.
这是我的代码,

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" >
    </asp:ScriptManager>
<div>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label><br />
        <asp:Button ID="Button1" runat="server" Text="PostBack" OnClick="Button1_Click" />
    </ContentTemplate>
    </asp:UpdatePanel>
</div>
protected void Button1_Click(object sender,EventArgs e)
{
    Label1.Text = DateTime.Now.ToLongTimeString()+UpdatePanel1.IsInPartialRendering+ScriptManager1.IsInAsyncPostBack;
}

谷歌和stackoverflow到目前为止对我没有帮助.所以善良的心帮助我……

解决方法

控制内部更新面板导致异步回发.
什么是异步回发?
从Refrence到MSDN

异步回发的行为很像同步回发.发生所有服务器页面生命周期事件,并保留视图状态和表单数据.但是,在呈现阶段,只有UpdatePanel控件的内容被发送到浏览器.页面的其余部分保持不变.

现在,如果它导致服务器上的所有事件比使用部分渲染…

Partial-page rendering removes the need for the whole page to be refreshed as the result of a postback. Instead,only individual regions of the page that have changed are updated. As a result,users do not see the whole page reload with every postback,which makes user interaction with the Web page more seamless

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读