简体   繁体   English

使用ASP.NET Web窗体,通用处理程序和jQuery上传文件

[英]Uploading Files Using ASP.NET Web Forms, Generic Handler and jQuery

I am following this article http://www.binaryintellect.net/articles/f2a2f1ee-e18a-416b-893e-883c800f83f4.aspx 我下面这篇文章http://www.binaryintellect.net/articles/f2a2f1ee-e18a-416b-893e-883c800f83f4.aspx

I am unable to get it to work. 我无法使其正常工作。 I use chrome to look at the javascript when it's running and it saying var fileUpload = $("#FileUpload1").get(0); 我使用Chrome来看看当它运行JavaScript和它说VAR的FileUpload = $(“#FileUpload1”)得到(0); is undefined. 未定义。 When I look in the html portion, this is what it generated 当我查看html部分时,这就是它生成的

 <input type="file" name="ctl00$ContentPlaceHolder1$FileUpload1" id="ContentPlaceHolder1_FileUpload1" />

I am using jquery 1.9 and asp.net webform. 我正在使用jQuery 1.9和asp.net Webform。 Any advice? 有什么建议吗?

The goal is to only upload certain file extension and display back to user if upload was successful or invalid file extension. 我们的目标是只能上传特定文件扩展名,并显示回用户如果上传成功或无效的文件扩展名。

Try 尝试

$("#ContentPlaceHolder1_FileUpload1")

With an id selector there is really no reason to treat it like a list of jQuery elements. 使用id选择器,实际上没有理由将其视为jQuery元素列表。

Also, you can disable this feature that garbles up ids in ASP.NET. 另外,您可以禁用此功能,使ASP.NET中的ID乱码。

You can use a wildcard in jquery to find any elements that end with "FileUpload1", essentially ignoring all the extra content ASP.NET generates with the following: 您可以在jquery中使用通配符查找以“ FileUpload1”结尾的任何元素,而实际上忽略了ASP.NET通过以下内容生成的所有额外内容:

$("[id$=FileUpload1]")

That should work for you. 那应该为您工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM