我有一个文件上传控件和一个jquery对话框内的按钮,但点击不点火这里是我的aspx页面:
<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>
这是代码隐藏的代码:
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;
});
});
点击工作在jquery对话框之外正常工作但在其中它不起作用 使用asp.net 4.0和jquery 1.4.1 vs edition。
感谢
答案 0 :(得分:4)
它实际上不起作用,因为当你的jQuery对话框是外部表单标签时。因此,您的按钮不在表单标记内,并且不会触发表单的提交事件。
如果要触发事件,请尝试在窗体内添加整个对话框。
答案 1 :(得分:2)
首先将div放在form标签中,然后尝试按照jquery代码片段
$(function () {
$("#photoUpButton").click(function (pho) {
$(".pUploadDiv").css("visibility", "visible").dialog({
modal: true,
height: 300,
autoOpen: true
}, "draggable");
$(".pUploadDiv").parent().appendTo($("form:first"));
});
});
修改强>
根据您的评论,我创建了一个示例页面。请查看并告诉我。如果您遇到任何问题。
<%@ 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));
}
}
}
}
答案 2 :(得分:0)
$('#divDialog').dialog({
bgiframe: true, autoOpen: false, height: 175,
width: 600, minWidth: 200, modal:
true,
open: function(type,data) {
$(this).parent().appendTo("form");
},
close: function(type,data) {
$(this).parent().replaceWith("");
}
});
尝试它会起作用..
参考:http://www.keysolutions.com/blogs/kenyee.nsf/d6plinks/KKYE-7XPVS6