2012-05-02 41 views
1

我有兩個列表框和一個左右按鈕..它們包含在一個updatepanel中。唯一的問題是,當點擊左側或右側按鈕時,頁面刷新是不期望的。ASP.NET在使用updatepanel時應該刷新頁面嗎?

<asp:UpdatePanel runat="server" ID="ExportUpdatePanel"> 
<ContentTemplate> 
    <div class="exportWrapper"> 
    <table class="exportFilter"> 
     <tr> 
      <td> 
       <h2> 
        <%= ExportSelectDateLabel %></h2> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <label> 
        <%= ExportFromDateLabel %></label> 
       <asp:TextBox runat="server" ID="exportFilterFromDate" CssClass="exportDates"></asp:TextBox> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <label> 
        <%= ExportToDateLabel %></label> 
       <asp:TextBox runat="server" ID="exportFilterToDate" CssClass="exportDates"></asp:TextBox> 
      </td> 
     </tr> 
    </table> 
    <table class="exportFilter"> 
     <tr> 
      <td colspan="3"> 
       <h2> 
        <%= ExportSelectColumnsLabel %></h2> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <label> 
        <%= ExportAvailableColumnLabel %></label> 
      </td> 
      <td> 
      </td> 
      <td> 
       <label> 
        <%= ExportSelectedColumnLabel %></label> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <asp:ListBox runat="server" ID="exportFilterAvailableColumns" SelectionMode="Multiple" CssClass="exportListBox"> 
       </asp:ListBox> 
      </td> 
      <td class="exportButtonsTd"> 
       <div> 
        <asp:LinkButton runat="server" OnClick="MoveSelectedClick"><span><img src="/images/source/arrow-right.png" alt="Move Right"/></span></asp:LinkButton> 
       </div> 
       <div class="mt_10"> 
        <asp:LinkButton runat="server" OnClick="RemoveSelectedClick"><span><img src="/images/source/arrow-left.png" alt="Move Left"/></span></asp:LinkButton> 
       </div> 
      </td> 
      <td id="exportedSelectedColumn"> 
       <asp:ListBox runat="server" ID="exportFilterSelectedColumns" SelectionMode="Multiple" CssClass="exportListBox"> 
       </asp:ListBox> 
      </td> 
     </tr> 
    </table> 
</div> 
</ContentTemplate> 
</asp:UpdatePanel> 

任何想法?

+1

你的意思是_refresh_?它是否執行完整的回發或異步回發,這是不希望的? –

+0

正如在頁面回發瀏覽器窗口刷新 – StevieB

回答

1

根據您的代碼,ExportUpdatePanel部分將在您點擊UpdatePanel內的鏈接按鈕時刷新。它不是全頁面刷新。更新面板的默認更新模式始終是。這意味着: UpdatePanel控件的內容在源自頁面任何位置的每次回傳中都會更新。這包括來自其他UpdatePanel控件內的控件的異步回發以及不在UpdatePanel控件內的控件的回發。

這裏是樣品測試:

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
    <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
     <ContentTemplate> 
      <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 
      <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> 
     </ContentTemplate> 
</asp:UpdatePanel> 

在click事件都label1和label2將更新。

protected void Button1_Click(object sender, EventArgs e) 
{ 
    Label1.Text = DateTime.Now.ToLongTimeString(); 
    Label2.Text = DateTime.Now.ToLongTimeString(); 
} 

但只有Label2會更改,因爲它會刷新更新面板。

0

在使用更新面板之前,請閱讀關於更新面板如何工作的文章。例如,這一個:http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers

UpdateMode="Conditional"ChildrenAsTriggers="true"屬性添加到您的更新面板,它應該按照您的要求工作。

<asp:UpdatePanel runat="server" 
    ID="ExportUpdatePanel" 
    UpdateMode="Conditional" 
    ChildrenAsTriggers="true"> 
+0

嘿謝謝你的回覆,但仍然得到頁面刷新發生即使與上述。 – StevieB