2011-04-15 67 views
2

我有一個「遺留」的ASP.NET網站,我想提高一點。我想要做的一件事就是更新頁面 - 目前,它總是全面更新,但我想開始使用部分更新。UpdatePanel和主頁面中的兩個內容佔位符區域

我一直希望能夠使用ASP.NET UpdatePanel這個 - 但我有點卡住如何讓這個爲我工作。

我有一個母版頁,其定義了一些內容佔位符 - 簡化它看起來像這樣:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Default.master.cs" Inherits="WebForms_Default" %> 
<?xml version="1.0" encoding="utf-8" ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title>MyTitle</title> 
</head> 
<body> 
    <form id="myForm" runat="server"> 
     <asp:ScriptManager ID="smgrMaster" runat="server" LoadScriptsBeforeUI="true"> 
     <Scripts> 
      <asp:ScriptReference Path="~/Scripts/jquery-1.4.2.min.js" /> 
     </Scripts> 
     </asp:ScriptManager> 
     <asp:ContentPlaceHolder runat="server" ID="cphSearch" /> 
     <asp:ContentPlaceHolder runat="server" ID="cphContent" /> 
    </form> 
</body> 
</html> 

在我的內容頁,我的網格顯示cphContent區域內的數據 - 在我cphSearch區我有一些輸入控件 - 一個RadioButtonList和兩個DropDowns。只要這些控件中的某些內容發生更改,現在就會發布回發(它們有AutoPostback="true"集)。

我的問題是:我怎麼告訴我UpdatePanel(這我想在我的包裹格在cphContent區)爲「監聽」從cphSearch這三個控件回發?

<asp:UpdatePanel> 
    <ContentTemplate> 
     <asp:GridView> 
     // grid view defined here 
     </asp:GridView> 
    </ContentTemplate> 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID=".. what values to put here?? .." /> 
     <asp:PostBackTrigger ControlID=".. - what values to put here?? .." /> 
    </Triggers> 

當我加我<asp:UpdatePanel>,我得到一個部分<Triggers>,但在cphSearch內容區域的控制是不可見的,所以我想我不能真正增加他們作爲UPDATE觸發器,正確?

要麼我完全沒有得到它(絕對有可能!),要麼我錯過了一個明顯的步驟/訣竅讓它起作用 - 否則它是不可能的。讓我知道!

回答

2

我認爲它沒有必要把Triggers當你不能夠找到控制Triggers一些事件只是使用的UpdatePanel所有的時間不triggers

<asp:Content ID="Content1" ContentPlaceHolderID="cphSearch" runat="Server"> 
    <asp:UpdatePanel ID="updateSearch" runat="server"> 
    <ContentTemplate> 
     your searching controls 
    </ContentTemplate> 
    </asp:UpdatePanel> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="cphContent" runat="Server"> 
    <asp:UpdatePanel ID="updateContent" runat="server"> 
    <ContentTemplate> 
     your grid 
    </ContentTemplate> 
    </asp:UpdatePanel> 
</asp:Content> 

這將更新整個電網,搜索控件,它會也處理AutoPostBack事件,但DENT忘記把更新<asp:UpdateProgress>控制看到工作正在進行中...

+0

不知道爲什麼 - 但這似乎工作 - 謝謝!我始終覺得你不得不告訴UpdatePanel哪些事件會觸發部分頁面更新...... – 2011-04-18 07:12:13

0

從這些信息,我假設你有MasterPage上的搜索控件是所有頁面通用的。一種方法是從您的母版頁公開事件並在您的內容頁面上處理它。檢查this

當您的DDL selectedIndexChanged事件引發此事件時。在contentPage上的這個事件的處理程序中,您可以調用updateContent.Update()。

我認爲解決方案存在於這些方面。

+0

不完全 - 這些搜索控件依賴於顯示的內容 - 它們在ContentPlaceHolder(在母版頁中定義)內部, - 但它們在母版頁上不是**而不是**(對於所有內容頁面它們也不一樣) – 2011-04-15 21:02:36

+0

因此,您的GV和搜索控件是您所指的相同內容頁的一部分?我沒有清晰的圖像。你能否更新包含搜索控制的代碼? – gbs 2011-04-15 21:09:15

+0

否 - 搜索控件位於一個文件中,並放置在「cphSearch」容器中,而gridview位於另一個文件中,並放置在「cphContent」容器 – 2011-04-16 08:00:46

相關問題