views:

68

answers:

1

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

+1  A: 

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.
Nick Craver
I think you also need to call UpdatePanel2.Update() in your code-behind to update the panel as well, I think...
Mantorok
@Mantorok - Depends when he *does* want it updated, added the relevant docs for this, if he only wants it updated when a control inside it causes it, then that's taken care of...but yes when updated externally you need to call `.Update()`.
Nick Craver
Thank you Craver, worked like a charm
Raul