我有此相同的问题。我认为你想要做的是为你想要在你的页面上展示的每个uploadify实例进行用户控制。我的工作uploadify控制的实例:
//ascx
<style type="text/css">
.hidden { display:none; }
</style>
<script src="/Uploadify/jquery.uploadify.v2.1.4.js" type="text/javascript"></script>
<script src="/Uploadify/jquery.uploadify.v2.1.4.min.js" type="text/javascript"></script>
<script src="/Uploadify/swfobject.js" type="text/javascript"></script>
<link href="/Uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function() {
var obj = document.getElementById('<%= this.fileInput.ClientID %>');
$(obj).uploadify({
'uploader': '/uploadify/uploadify.swf',
'script': '/_handlers/Upload.ashx',
'cancelImg': '/uploadify/cancel.png',
'auto': true,
'multi': true,
'fileDesc': 'Image Files',
'fileExt': document.getElementById('<%= this.uTypes.ClientID %>').value,
'buttonText': 'Choose Images',
'folder': '/' + document.getElementById('<%= this.fileDest.ClientID %>').value,
'onAllComplete': function (event, queueID, fileObj, response, data) {
var btn = document.getElementById('<%= this.uploadButton.ClientID %>').click();
}
});
});
</script>
<input id="fileInput" name="fileInput" type="file" runat="server" style="display:none" />
<input id="fileDest" name="fileDest" type="text" runat="server" style="display:none"/>
<input id="uTypes" name="uTypes" type="text" runat="server" style="display:none"/>
<asp:Button ID="uploadButton" runat="server" CssClass="hidden" OnClick="uploadButton_Clicked" CausesValidation="false"/>
这是背后的控制的部分代码,您看到传递在外部
//Code behind
public partial class UploadifyUpload : System.Web.UI.UserControl
{
private string fileDestination;
public string FileDestination
{
get { return fileDestination; }
set { fileDestination = value; }
}
private string uploadTypes;
public string UploadTypes
{
get { return uploadTypes; }
set { uploadTypes = value; }
}
public event EventHandler UploadButtonClicked;
protected void Page_Load(object sender, EventArgs e)
{
string virtualPath = fileDestination.Replace(Request.PhysicalApplicationPath, "/");
virtualPath = virtualPath.Replace('\\', '/');
this.fileDest.Value = virtualPath;
this.uTypes.Value = uploadTypes;
}
protected void uploadButton_Clicked(object sender, EventArgs e)
{
if (this.UploadButtonClicked != null)
{
this.UploadButtonClicked(this, new EventArgs());
}
}
}
我创建这样的控制和传递的参数几个变量。文件目标和单击事件在任何使用该控件的页面的代码隐藏中处理。
<mgmtControls:UploadifyUpload ID="uploadifyUpload" runat="server" UploadTypes="*.jpg;*.png;*.gif;*.bmp;*.jpeg" />
this.uploadifyUpload.UploadButtonClicked += new EventHandler(UploadifyUploadClicked);
this.uploadifyUpload.FileDestination = DocumentPath;
这对我在Firefox,Chrome和IE中非常适用,它应该引导您朝着正确的方向前进。如果用户没有安装Flash,您可能需要考虑添加默认上传选项。
这个解决方案对我很好。它在这个页面上需要更多的认可。谢谢。 – tmutton
这是一个很好的解决方案。我用'$'替换了“jQuery”,缩短了一点。谢谢@Havanasud。 –
我认为这应该没有每个循环。 – sumit