2011-05-02 148 views
1

我有一個FileUpload控件和一個jQuery對話框內的按鈕,但在上點擊這裏不火是我的aspx頁面內不工作:上點擊一個jQueryUI的對話框

<div id="pUploadDiv" class="pUploadDiv"> 
     <asp:FileUpload runat="server" ID="FileUpload1" CssClass="FileUpload" /><br /> 
      <asp:FileUpload runat="server" ID="FileUpload2" CssClass="FileUpload" /><br /> 
      <asp:FileUpload runat="server" ID="FileUpload3" CssClass="FileUpload" /><br /> 
      <asp:FileUpload runat="server" ID="FileUpload4" CssClass="FileUpload" /><br /> 
       <asp:Button runat="server" ID="UploadButton" Text="Upload" OnClick="test" /> 
    </div> 

這裏是代碼-behind:

try 
    { 
     HttpFileCollection hfc = Request.Files; 
     for (int i = 0; i < hfc.Count; i++) 
     { 
      HttpPostedFile hpf = hfc[i]; 
      if (hpf.ContentLength > 0) 
      { 
       hpf.SaveAs(Server.MapPath("imgs") + "\\" + Path.GetFileName(hpf.FileName)); 
      } 
     } 
    } 
    catch {} 

,最後我的jquery:

$(function() { 
$("#photoUpButton").click(function (pho) { 
    $(".pUploadDiv").css("visibility","visible").dialog({ 
     modal: true, 
     height: 300 
    }, "draggable"); 
    return false; 
}); 

});

on-click在jquery對話框外工作正常,但在裏面它不工作 使用asp.net 4.0與jquery 1.4.1與版本。

感謝

回答

2

首先把你的div表單標籤內,然後嘗試以下的jQuery代碼片斷

$(function() { 
      $("#photoUpButton").click(function (pho) { 
       $(".pUploadDiv").css("visibility", "visible").dialog({ 
        modal: true, 
        height: 300, 
        autoOpen: true 
       }, "draggable"); 
       $(".pUploadDiv").parent().appendTo($("form:first")); 
      }); 
     }); 

編輯

按照您的評論,我已經創建了一個樣本page.Please退房,讓我知道。如果您遇到任何問題。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %> 

<!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></title> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.js"></script> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script> 
    <script type="text/javascript"> 
     $(function() { 
      $("#btnOpen").click(function (pho) { 
       $(".pUploadDiv").css("visibility", "visible").dialog({ 
        modal: true, 
        height: 300, 
        autoOpen: true 
       }, "draggable"); 
       $(".pUploadDiv").parent().appendTo($("#form1")); 
      }); 
     }); 


    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <input type="button" id="btnOpen" value="Upload Files" /></div> 
    <div id="pUploadDiv" class="pUploadDiv"> 
     <asp:FileUpload runat="server" ID="FileUpload1" CssClass="FileUpload" /><br /> 
     <asp:FileUpload runat="server" ID="FileUpload2" CssClass="FileUpload" /><br /> 
     <asp:FileUpload runat="server" ID="FileUpload3" CssClass="FileUpload" /><br /> 
     <asp:FileUpload runat="server" ID="FileUpload4" CssClass="FileUpload" /><br /> 
     <asp:Button runat="server" ID="UploadButton" Text="Upload" CausesValidation="true" 
      OnClick="UploadButton_Click" /> 
    </div> 
    </form> 
    <form id="form2" action=""> 
    I am on form2 
    </form> 
    <form id="form3" action=""> 
    I am on form2 
    </form> 
</body> 
</html> 

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

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


    } 
    protected void UploadButton_Click(object sender, EventArgs e) 
    { 
     HttpFileCollection hfc = Request.Files; 
     for (int i = 0; i < hfc.Count; i++) 
     { 
      HttpPostedFile hpf = hfc[i]; 
      if (hpf.ContentLength > 0) 
      { 
       // hpf.SaveAs(Server.MapPath("imgs") + "\\" + Path.GetFileName(hpf.FileName)); 
      } 
     } 
    } 
} 
+0

嘗試過但它對我無效 – Wahtever 2011-05-02 21:57:27

+0

@Wahtever:請分享您的完整標記代碼。 – 2011-05-03 07:43:40

+0

@geek - 這是我用'$(函數(){$ ( 「pUploadDiv。」)對話框({ 高度:200, 模式:真 }, 「拖動」); $ (本)。 .parent()。appendTo($(「#Form2」)); });' – Wahtever 2011-05-03 10:18:17

3

,因爲當你jQuery的對話是外在形式標籤不實際工作。所以你的按鈕不在表單標籤內,並且不會觸發表單的提交事件。

如果要觸發事件,請嘗試在表單中添加整個對話框。

+0

謝謝你,嘗試添加的形式,但沒有運氣裏面的對話,想我會只是使用顯示和隱藏。 – Wahtever 2011-05-02 12:51:53

+0

以下是Mamoon正在談論的內容的解釋:http://www.keysolutions.com/blogs/kenyee.nsf/d6plinks/KKYE-7XPVS6 – SquidScareMe 2011-05-02 13:09:59