2009-10-14 67 views
0

我正在構建一個ASP.NET應用程序,並希望使用母版頁來顯示品牌和導航信息,並在幾個內容頁面中移動。但是,每次嘗試加載新內容時,整個頁面都會閃爍。無論如何要避免這種情況?如何讓主頁面不閃爍?

母版頁:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="Interface.Site" %> 
    <%@ Register TagPrefix="customControl" TagName="NavigationBar" Src="NavigationControl/NavigationControl.ascx" %> 
    <!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>Registration</title> 
    <asp:ContentPlaceHolder ID="head" runat="server"> 
    </asp:ContentPlaceHolder> 
    <link href="Stylesheet.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
    <form id="RegistrationMasterForm" runat="server"> 
    <div> 
    <asp:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true"> 
     </asp:ScriptManager> 

     <%-- Contents of this div span the top of the page for branding --%> 
     <div id="BrandingBanner"> 
      <asp:Image ID="Banner" runat="server" 
       ImageUrl="Images/BrandingBanner.png"/> 
     </div> 

     <%-- Navigation Bar, the contents of this div should remain unchanged --%> 
     <div id="NavigationBar"> 
      <customControl:NavigationBar ID="navBar" runat="server"/> 
     </div> 

     <%-- Contains any forms or controls that may be uniquie to the page --%> 
     <div id="FormControls"> 
      <div id="FormContent">    
       <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">   
       </asp:ContentPlaceHolder> 
      </div>    
     </div> 

    </div> 
    </form> 
</body> 
</html> 

內容:

<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="Interface.WebForm2" Title="Untitled Page" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> 

     <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
      <ContentTemplate> 
       Check me out! I am content for the master page! 
       <asp:Button ID="Button1" runat="server" Text="Next" onclick="Button1_Click" /> 
      </ContentTemplate> 
     </asp:UpdatePanel> 
</asp:Content> 

內容背後的代碼:

public partial class WebForm2 : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 

    protected void Button1_Click(object sender, EventArgs e) 
    { 
     Response.Redirect("WebForm3.aspx"); 
    } 
} 
+0

因爲你正在做一個Response.Redirect而閃爍。我認爲有辦法動態地將控件加載到同一頁面,但我沒有嘗試過。 – Greg 2009-10-14 18:50:57

+0

我現在確信我的重定向是壞的,但任何人都可以建議如何更改內容,同時避免閃爍? – ProgrammingPope 2009-10-14 19:24:08

回答

1

控件事件會觸發一個回傳到您的頁面的頁面,這通常會創建您看到的「空白」效果。爲了緩解這種情況,您可能需要考慮使用某種Ajax解決方案來導致部分回發或異步回發以防止「消隱」。

但是在你點擊按鈕的特殊情況下,如果你正在試圖做的是把使用到另一個頁面,你真的應該只使用一個<a href="WebForm3.aspx">標籤,避免使用的Response.Redirect。

+0

不會消除閃爍,但它現在真的只在Chrome中顯着。 – ProgrammingPope 2009-10-15 21:22:08

0

心不是這個唯一可能的,如果你使用的是幀?據我所知,母版頁和內容頁在服務器端綁定在一起,並將整個客戶端壓下。

你想要什麼地方聽起來像使用頁面進行品牌和導航與內聯框架來提供您的修道院。這將防止外部頁面在客戶端「閃爍」。

編輯:雖然這不是做事的新方法。你可能想看看使用UpdatePannel或其他AJAX風格設計的東西。

0

您正在您的代碼隱藏中重定向頁面。 這會導致瀏覽器更改頁面,並重新繪製整個內容,至少IIRC。我在很久以前沒有使用過更新面板。

0

您不需要移動更新面板,您的重定向導致瀏覽器加載新頁面。