开发者

AJAX.NET __doPostBack changes other content

开发者 https://www.devze.com 2023-01-01 07:11 出处:网络
I have an application where a javascript reads the GPS location of the device and sends it to serverside script like this:

I have an application where a javascript reads the GPS location of the device and sends it to serverside script like this:

f()
{
  var initialLocation= Someshit();
  document.getElementById('<% = text.ClientID %>').value=initialLocation;
  var button = document.getElementById('<% = Button4.ClientID %>');
  button.click();
}

And i have some AJAX.NET code:

<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>

And a bit further down

<asp:UpdatePanel ID="UpdatePanel2" runat="server">
   <ContentTemplate>
      <div>
          <some divs and asp:gridviews and god knows what >
      </div>
    <ContentTemplate>
</asp:UpdatePanel>

The problem is that the the last divs inner content changes when the开发者_JAVA技巧 event of UpdatePanel1 has finished. Why is that? I don't want the content outside of UpdatePanel1 to be changed whenever UpdatePanel1 is doing its thing. Please help.


The default UpdateMode is Always, in this case you want Conditional, like this:

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
   <ContentTemplate>
      <div>
          Yadda yadda
      </div>
    <ContentTemplate>
</asp:UpdatePanel>

From MSDN, here's the difference:

  • Always - The content of the UpdatePanel control is updated for all postbacks that originate from the page. This includes asynchronous postbacks.

  • Conditional - The content of the UpdatePanel control is updated under the following conditions:

    • If the Update 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 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.
0

精彩评论

暂无评论...
验证码 换一张
取 消