2017-02-14 117 views
0

我有兩個asp控件:一個FileUpload和一個按鈕 在FileUpload上,我添加uploadify屬性,它的工作原理 我也想使用按鈕在代碼隱藏上做一些操作,然後調用文件上傳,但該文件彈出窗口不會出現從代碼隱藏調用Uploadify

出於測試目的,我試圖減少對客戶端的所有,但它仍然無法工作......

這裏是我的三個標籤

<asp:Button Text="Browse" OnClick="Carica_File_Click" runat="server" ID="UploadButton" CssClass="Load_Button" align="center"/> 
<asp:Button Text="BrowseFromClient" OnClientClick="openfileDialog();" runat="server" ID="Button1" CssClass="Load_Button" align="center"/> 
<asp:FileUpload runat="server" ID="FileUploadMain" align="center" /> 

客戶si德

<script type="text/javascript"> 
    $(window).load(
     function() { 
      $("#ContentPlaceHolderMain_FileUploadMain").uploadify({ 
       'swf': '../Scripts/uploadify.swf', 
       'cancelImg': '../images/uploadify-cancel.png', 
       'buttonText': 'Browse Files', 
       'uploader': '../FrontEnd/Upload.ashx<%=GetUploadParams()%>', 
       'folder': '', 
       'fileDesc': 'UPLOAD FILES', 
       'fileExt': '*.jpg;*.jpeg;*.gif;*.png;*.pdf;*.doc;*.docx', 
       'multi': true, 
       'auto': true, 
       'buttonImage': '<%=GetUploadFileUrl()%>', 
       'width': 217, 
       'removeTimeout': 1, 
       'removeCompleted': false, 
       'buttonClass': '', 
       'onUploadSuccess': function() { 
        location.reload(true); 
       } 

      }); 
     } 
    ); 
</script> 
<script> 
     function openfileDialog() { 
      $("#FileUploadMain").click(); 
     } 
</script> 

服務器端

Protected Sub Carica_File_Click(sender As Object, e As EventArgs) 
    Dim ClientID As String = FileUploadMain.ClientID 
    ScriptManager.RegisterStartupScript(Me, Page.GetType, "Script", "document.getElementById('#" & ClientID & "').click();", True) 
    ...code 
End Sub 

我走到哪裏錯了?

回答

0

在端我沒有一個解決方法:

用於執行所述代碼我被迫上的文件被成功地上傳至極然後對代碼在Page_Load處理後面

 $(window).load(
      function() { 
       $("#ContentPlaceHolderMain_FileUploadMain").uploadify({ 
        ....parameters 
        'onUploadSuccess': function (file, data, response) { 
         location.reload(true); 
         var ObjF = file.name; 
         __doPostBack('FileLoaded', ObjF); 
        } 
       }); 
      } 
     ); 

的情況下的回傳標籤雖然點擊,據我所知不可能爲用戶的安全(因爲上傳點擊處理的代碼或隱藏的按鈕可能是危險的) 所以我隱藏了uploadify按鈕,並把它放在我可以處理的定製按鈕

   <div style="position:relative;" class="row box_upload"> 
        <div style="width:100%;"> 
         <asp:FileUpload runat="server" ID="FileUploadMain" align="center" /> 
        </div> 
        <asp:Button text="Browse" style="width:100%;height:100%;position:absolute;top:0;left:0;" runat="server" ID="UploadButton" return false;" ></asp:button> 
       </div> 

缺點是,與我這個客戶端點擊不能使用按鈕,因爲它由uploadify對象疊加點擊,但我會離開它時,它將是必要的(並與我不需要的回發方法其他任何東西)