使用FileUpload上传文件时用js给出提示...
2009-04-12 15:23
429 查看
其实很简单,主要是我没怎么好好看过js,所以还是想了一会儿才想出来。。。感觉这代码有种骗人的感觉
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!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>Upload</title> <mce:script type="text/javascript" language="javascript"><!-- function jsUpload(id,attributeName,attributeValue) { if(arguments[0] == null || arguments[1] == null || arguments[2] == null) return true; var v = document.getElementById(id); v.setAttribute(attributeName,attributeValue); return true; } // --></mce:script> </head> <body> <form id="form1" runat="server"> <div> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Label ID="Label1" runat="server" Text="Select a file to upload"></asp:Label> <br /> <asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload" /> </div> </form> </body> </html>
Code using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { btnUpload.Attributes.Add("onclick", "jsUpload('"+Label1.ClientID +"','innerText','Uploading');"); } } protected void btnUpload_Click(object sender, EventArgs e) { if (FileUpload1.HasFile) { try { FileUpload1.SaveAs(Server.MapPath("~/") + System.IO.Path.GetFileNameWithoutExtension(FileUpload1.PostedFile.FileName) + Guid.NewGuid().ToString() + System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName)); ClientScriptManager cs = this.ClientScript; cs.RegisterClientScriptBlock(this.Page.GetType(), "Upload", "alert('Successful!');", true); } catch { ClientScriptManager cs = this.ClientScript; cs.RegisterClientScriptBlock(this.Page.GetType(), "NotUpload", "alert('Failed!');", true); } } } }
相关文章推荐
- 使用FileUpload上传文件时用js给出提示...
- js实现文件上传功能 后台使用MultipartFile
- js动态创建fileupload控件,js判断上传文件的大小,超过指定的大小删除掉
- 使用ajaxfileupload.js进行文件上传,文件可以上传成功,但是不走success回调函数解决办法。
- java使用fileupload接收上传文件
- ASP.NET2.0中使用FileUpload上传文件,及文件大小设置
- 使用fileupload实现文件上传
- HTML5_纯JS实现上传文件显示文件大小,文件信息,上传进度_不使用JS库
- 使用 HTTP 上传 G 级的文件之 Node.js 版本
- 使用formdata()的原生js文件上传
- MVC4中使用Jquery.Multifile.js和Jquery.form.js一次上传多个文件
- ASP.NET2.0中FileUpload控件的使用(即ASP.NET2.0中如何上传文件)
- 通过bootstrap-fileupload上传文件时js库修改为默认中文的方法
- 使用Ajaxupload.js上传文件
- 在UpdatePanel上使用FileUpload上传文件(转)
- 使用FileUpload组件实现文件上传
- Angular2-primeNG文件上传模块FileUpload使用详解
- 使用FileUpload组件上传文件
- JS中使用FormData上传文件、图片的方法
- JSP Servlet学习笔记——使用fileupload上传文件