首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AJAX.NET __doPostBack更改其他内容

AJAX.NET __doPostBack更改其他内容
EN

Stack Overflow用户
提问于 2010-05-26 14:56:03
回答 1查看 619关注 0票数 1

我有一个应用程序,其中javascript读取设备的GPS位置并将其发送到服务器端脚本,如下所示:

代码语言:javascript
复制
f()
{
  var initialLocation= Someshit();
  document.getElementById('<% = text.ClientID %>').value=initialLocation;
  var button = document.getElementById('<% = Button4.ClientID %>');
  button.click();
}

我有一些AJAX.NET代码:

代码语言:javascript
复制
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
       <asp:Button ID="Button4" runat="server" Text="PlaceHolder" onclick="Button4_Click"/>
       <asp:TextBox ID="text" runat="server"></asp:TextBox>
    </ContentTemplate>
</asp:UpdatePanel>

再往下一点

代码语言:javascript
复制
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
   <ContentTemplate>
      <div>
          <some divs and asp:gridviews and god knows what >
      </div>
    <ContentTemplate>
</asp:UpdatePanel>

问题是,当UpdatePanel1事件结束时,最后一个div内部内容会发生变化。为什么会这样呢?我不希望UpdatePanel1之外的内容在UpdatePanel1做它的事情时被更改。请帮帮忙。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-05-26 14:59:02

默认的UpdateModeAlways,在本例中您需要Conditional,如下所示:

代码语言:javascript
复制
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
   <ContentTemplate>
      <div>
          Yadda yadda
      </div>
    <ContentTemplate>
</asp:UpdatePanel>

来自MSDN,这里的区别是:

  • 始终是-- UpdatePanel控件的内容将被更新,用于所有源自页面的回发。这包括异步回发。
  • 条件-在以下条件下更新UpdatePanel控件的内容:
代码语言:javascript
复制
- If the [`Update`](http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.update.aspx) method of the UpdatePanel control is called explicitly.
- If a control is defined as a trigger by using the Triggers property of the UpdatePanel control and causes a postback. In this scenario, the control is an explicit trigger for updating the panel content. The trigger control can be either inside or outside the UpdatePanel control that defines the trigger.
- If the [`ChildrenAsTriggers` property](http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.childrenastriggers.aspx) is set to true and a child control of the UpdatePanel control causes a postback. In this scenario, child controls of the UpdatePanel control are implicit triggers for updating the panel. Child controls of nested UpdatePanel controls do not cause the outer UpdatePanel control to be updated unless they are explicitly defined as triggers.

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2914080

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档