2010-05-26 14 views
1

我有一個應用程序,其中一個javascript讀取設備的GPS位置,並將其發送到服務器端腳本是這樣的:AJAX.NET __doPostBack改變其他內容

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

,我有一些AJAX.NET代碼:

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

,有點進一步下跌

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

的問題是,當UpdatePanel1的情況下完成了最後的div內的內容變化。這是爲什麼?我不希望UpdatePanel1以外的內容被更改。請幫忙。

回答

1

默認UpdateModeAlways,在這種情況下,你想Conditional,像這樣:

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

From MSDN,這裏的區別:

  • 始終 - UpdatePanel控件的內容已針對源自頁面的所有回發進行更新。這包括異步回發。

  • 條件 - UpdatePanel控件的內容在下列情況下更新:

    • 如果UpdatePanel控件的Update方法顯式調用。
    • 如果通過使用UpdatePanel控件的Triggers屬性將控件定義爲觸發器並導致回發。在這種情況下,控件是更新面板內容的顯式觸發器。觸發器控件可以在定義觸發器的UpdatePanel控件的內部或外部。
    • 如果ChildrenAsTriggers property設置爲true,並且UpdatePanel控件的子控件導致回發。在這種情況下,UpdatePanel控件的子控件是用於更新面板的隱式觸發器。嵌套UpdatePanel控件的子控件不會導致更新外部UpdatePanel控件,除非它們被明確定義爲觸發器。
+0

我想你也需要在你調用UpdatePanel2.Update()代碼隱藏更新面板,以及,我覺得... – Mantorok 2010-05-26 14:59:47

+0

@Mantorok - 依賴時,他不* *想要更新,爲此添加了相關文檔,如果他只想在它內部的控件導致它更新時更新,那麼這是照顧...但是當從外部更新時需要調用'.Update()'。 – 2010-05-26 15:02:55

+0

謝謝你Craver,工作就像一個魅力 – Raul 2010-05-26 15:11:54