2013-07-25 89 views
1

包括以下是我的,因爲我已經使用FineUploader控件的頁面標記。我刪減了代碼,只包含了重要的部分。該頁面分爲兩部分,它們都位於UpdatePanel中。第一部分是一個包含數據行的簡單表格,每行的最後一列是一個asp:LinkBut​​ton。第二部分是包含在其中第一加載頁面時的FineUploader控制呈現(因爲FineUploader控制是嚴格的JavaScript和不會在代碼隱藏進一步存在)一個div嵌套的UpdatePanel。此外,按下LinkBut​​ton時this.Page.IsPostBackfalseUpdatePanel的問題只控制

的問題是,在頁面的第一部分一個LinkBut​​ton按下任何時候,FineUploader控制簡單地消失。我無法從代碼隱藏中重新呈現代碼(例如ClientScript.RegisterStartupScript/RegisterClientScriptBlock)。我也嘗試過用UpdatePanel封裝第1部分的各種設置,但它仍然消除了我的FineUploader控件。我想我錯誤地使用更新面板,但我不確定(ASP.NET通常不是我工作的)。

作爲一個額外的細節,如果我點擊第2部分嵌套UpdatePanel內的按鈕,我FineUploader控制奇蹟般地再次出現。

標記(能見度重要的部分都標有多線路,大部分是空的註釋塊):

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Setup.aspx.cs" Inherits="Some_Portal.Pages.Setup" %> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> 
    <div id="locationInfo"> 
     <br class="clearfloat" /> 
     <!-- Main Screen Display breaking down the types of information --> 
     <asp:UpdatePanel runat="server" ID="updExtensions"> 
     <Triggers> 
     <asp:PostBackTrigger ControlID="btnDownloadCall" /> 
     </Triggers> 
     <ContentTemplate> 

     <script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script> 

    <style type='text/css'> 
    .filename { 
    visibility: hidden; 
    height: 0; 
    width: 0; 
    display: block; 
} 
    </style> 

<!-- This portion is to enable the file uploader: --> 
<link href="../js/fineuploader/fineuploader-3.5.0.css" rel="stylesheet"> 
<script type="text/javascript" src="../js/fineuploader/fineuploader-3.5.0.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     var uploader = new qq.FineUploader({ 
     element: $('#fine-uploader')[0], 
     request: { 
      endpoint: 'AccountSetup.aspx' 
     }, 
     autoUpload: true, 
     multiple: false, 
     text: { 
      uploadButton: '<asp:Button ID="fineUploadButton" runat="server" CssClass="button" style="width:6;5" Text="Browse" />' 
     }, 
     validation: { 
      allowedExtensions: ['mp3', 'wav'] 
     } 
     }); 
    }); 
</script> 


      <!--        --> 
      <!--        --> 
      <!--   Part 1   --> 
      <!--        --> 
      <!--        --> 
      <table width="100%" cellpadding="0" border="0px" style="border-color:white;"> 
       <tr> 
        <th>Extensions</th> 
       </tr> 
       <tr> 
        <td style="width: 100%; border:0; border-bottom-color:white; border-bottom-style:none;"> 
        <asp:DataGrid ID="dgExtensions" runat="server" AllowSorting="true" AllowPaging="true" PagerStyle-BorderStyle="None" PagerStyle-BorderColor="white" PagerStyle-BorderWidth="0px" 
         AutoGenerateColumns="false" PageSize="10" DataKeyField="id" OnPageIndexChanged="dgExtensions_OnPageIndexChanged" 
         PagerStyle-Mode="NumericPages" PagerStyle-HorizontalAlign="Right" OnSortCommand="dgExtensions_OnSortCommand"       
         Width="100%" BorderColor="White" 
        HeaderStyle-CssClass="GridHeader" 
         ItemStyle-CssClass="GridItem" 
        AlternatingItemStyle-CssClass="GridAltItem"> 
         <Columns> 
          <asp:BoundColumn DataField="number" HeaderText="Number" SortExpression="number"> 
           <ItemStyle HorizontalAlign="center" Width="8%" /> 
           <HeaderStyle HorizontalAlign="center" Width="8%" /> 
          </asp:BoundColumn> 
          <asp:BoundColumn DataField="extensionType" HeaderText="Type" SortExpression="extensionType"> 
           <ItemStyle HorizontalAlign="center" Width="18%" /> 
           <HeaderStyle HorizontalAlign="center" Width="18%" /> 
          </asp:BoundColumn> 
          <asp:TemplateColumn HeaderText="Description" SortExpression="description"> 
           <HeaderStyle Width="25%" CssClass="dgLeftPad" /> 
           <ItemStyle Width="25%" CssClass="dgLeftPad" /> 
           <ItemTemplate> 
           <asp:Literal runat="Server" ID="litExtensionDescription" Text='<%# Eval("description").ToString() %>' /> 
           <asp:HiddenField runat="server" ID="hidExtensionID" Value='<%# Eval("id").ToString() %>' /> 
           <asp:HiddenField runat="server" ID="hidExtensionTypeID" Value='<%# Eval("extensiontypeid").ToString() %>' /> 
           <asp:HiddenField runat="server" ID="hidPrevDescription" Value='<%# Eval("description").ToString() %>' /> 
           </ItemTemplate> 
          </asp:TemplateColumn> 
          <asp:BoundColumn DataField="status" HeaderText="Status" SortExpression="status"> 
           <ItemStyle HorizontalAlign="center" Width="24%" /> 
           <HeaderStyle HorizontalAlign="center" Width="24%" /> 
          </asp:BoundColumn>      
          <asp:TemplateColumn HeaderText=""> 
           <HeaderStyle Width="10%" /> 
           <ItemStyle Width="10%" HorizontalAlign="center" /> 
           <ItemTemplate> 
           <!--        --> 
           <!--        --> 
           <!-- Clicking this makes the Fine --> 
           <!-- Uploader control go away. --> 
           <!--        --> 
           <!--        --> 
           <asp:LinkButton runat="Server" ID="lbEditExtension" CommandArgument='<%# Eval("id").ToString() %>' 
            OnCommand="EditExtension" Text="Edit" Visible='<%# SetEditEnabled(Eval("extensiontypeid").ToString()) %>'/> 
           </ItemTemplate> 
          </asp:TemplateColumn> 
         </Columns> 
         <HeaderStyle BackColor="#eeeeee" /> 
         <PagerStyle HorizontalAlign="Right" Mode="NumericPages" /> 
        </asp:DataGrid> 
        </td> 
       </tr> 
       <tr> 
        <asp:Panel runat="server" ID="pnlNoExtensions"> 
        <td colspan="3" align="center" style="color: Red;"> 
         There are no extensions established for your account 
        </td> 
        </asp:Panel> 
       </tr> 
      </table> 
      <br /> 


      <!--        --> 
      <!--        --> 
      <!--   Part 2   --> 
      <!--        --> 
      <!--        --> 
      <asp:Panel runat="server" ID="Panel1" Width="100%"> 
      <asp:UpdatePanel runat="server" ID="updRouteGroup" UpdateMode="Conditional"> 
       <Triggers> 
       <asp:PostBackTrigger ControlID="btnDisableOnHold" /> 
       </Triggers> 
       <ContentTemplate>   
       <asp:Panel ID="pnlImpExcel" runat="Server" > 
       <div style="width:100%"> 
       <table colspan="0" width="100%" cellpadding="0" cellspacing="0"> 
        <tr> 
        <th colspan="3"> 
         On Hold Music 
        </th> 
        </tr> 
        <tr> 
        <!--        --> 
        <!-- FineUploader Control  --> 
        <!--        --> 
        <td align="left" valign="middle"><div id="fine-uploader"></div></td> 
        <td align="center" valign="middle"><asp:Label ID="lblOnHoldFile" runat="server" Text="Current file: none"/></td> 
        <td align="right" valign="middle"><asp:Button ID="btnDisableOnHold" runat="server" style="margin-right:7px;width:87px;" Text="Disable Hold Music" CssClass="button" OnClick="btnDisableOnHold_OnClick" /></td> 
        </tr>    
        <tr><td colspan ="2" align="center"><asp:Label runat="server" ID="lblUploadError" style="color: Red;" Visible="false" /></td></tr> 
       </table> 
       </div> 

       </asp:Panel> 
       </ContentTemplate> 
      </asp:UpdatePanel> 
      </asp:Panel> 

      <!-- The Operator Extension Panel --> 
      <asp:Panel runat="server" ID="Panel2"> 
      <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional"> 
       <Triggers> 
       <asp:PostBackTrigger ControlID="btnOperatorUpdate" /> 
       </Triggers> 

       <ContentTemplate>   
       <asp:Panel ID="Panel3" runat="Server" > 
       <div> 
       <table colspan="0" width="100%" cellpadding="0" cellspacing="0"> 
        <tr> 
        <th colspan="3"> 
         Operator Extension 
         <asp:Button ID="btnOperatorUpdate" runat="server" Text="Save" CssClass="button" style="margin-right:2px;width:87px;float:right;padding-right:10px;" OnClick="btnOperatorUpdate_OnClick" />       
         <asp:DropDownList runat="Server" ID="ddlOperatorExtension" style="float:right;margin-right:10px;" Width="250px" AutoPostBack="false" /> 
        </th> 
        </tr>     
       </table> 
       <br /> 
       </div> 
       </asp:Panel> 
       </ContentTemplate> 
      </asp:UpdatePanel> 
      </asp:Panel> 



     </ContentTemplate> 
     </asp:UpdatePanel> 
    </div> 
</asp:Content> 

我怎樣才能讓我的FineUploader控制保持可見?

編輯1: 考慮到這可能是一個頁面生命週期的問題,我試圖通過添加以下控制的手動渲染:

protected void Page_Init(object sender, EventArgs e) 
    { 
    string script = "<script type=\"text/javascript\">" + 
         " alert('oh hey');" + 
         " $(document).ready(function() {" + 
         "  var uploader = new qq.FineUploader({" + 
         "   element: $('#fine-uploader')[0]," + 
         "   request: {" + 
         "   endpoint: 'AccountSetup.aspx'" + 
         "   }," + 
         "   autoUpload: true," + 
         "   multiple: false," + 
         "   text: {" + 
         "   uploadButton: '<asp:Button ID=\"fineUploadButton\" runat=\"server\" CssClass=\"button\" style=\"width:6;5\" Text=\"Browse\" />'" + 
         "   }," + 
         "   validation: {" + 
         "   allowedExtensions: ['mp3', 'wav']" + 
         "   }" + 
         "  });" + 
         " });" + 
         "</script>"; 
     ClientScript.RegisterClientScriptBlock(this.GetType(), "HideOnPostback", script, false); 

     System.Diagnostics.Debug.WriteLine("Page_Init() run"); 
    } 

其結果是,如果我點擊「編輯」的LinkBut​​ton在第1部分中,我在調試輸出中看到「Page_Init()運行」,但控件仍然消失,並且「哦,嘿嘿」js警報從不顯示。但是,如果我單擊第2部分中的其他按鈕,則會在調試輸出中看到「Page_Init()運行」,我看到「哦,嘿」警報,FineUploader按鈕仍然可見。

回答

3

我相信你遇到這個問題,因爲您加載的FineUploader控制太遲在頁面生命週期才能正常加載的ViewState。點擊該按鈕會觸發一個回傳,重新開始頁面的生命週期。 ViewState在Page_Load()之前加載,因此嘗試在Page_Init()期間將控件添加到頁面,以便可以加載ViewState。

+0

我試圖與相同的結果,當我把在'Page_Load'。我在編輯中添加了更多的細節以解決我原來的問題。 – kmarks2

+1

你在ScriptManager上設置EnablePartialRendering =「true」嗎?如果你這樣做,如果你圍繞第1部分的LinkBut​​ton封裝更新面板會發生什麼? – LoganGoesPlaces

+1

另一個可能的問題是控件ID在重新創建時需要保持不變。看起來你沒有這個問題,但它可能值得檢查,如果一切都失敗了。 – LoganGoesPlaces