zl程序教程

您现在的位置是:首页 >  后端

当前栏目

asp.net使用jQueryUploadify上传附件示例

NetASP上传 使用 示例 附件 JqueryUploadify
2023-06-13 09:15:15 时间

Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示。Uploadify官方网址:http://www.uploadify.com/,在MVC中使用的方法可以参考jQueryUploadify在ASP.NETMVC3中的使用和Asp.netMvc中使用uploadify实现图片缩放保存。

本文是一个简单的介绍Demo,主要是动态传递参数方法:通过formdata向处理程序传递额外的表单数据:

复制代码代码如下:

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
   <title></title>
   <linkhref="uploadify/uploadify.css"type="text/css"rel="Stylesheet"/>
   <scripttype="text/javascript"src="uploadify/jquery-1.7.2.min.js"></script>
   <scripttype="text/javascript"src="uploadify/swfobject.js"></script>
   <scripttype="text/javascript"src="uploadify/jquery.uploadify.min.js"></script>
   <scripttype="text/javascript">

       $(function(){
           vartaskId="<%=TaskID%>";
           varactivityId="<%=ActivityId%>";
           varuserId="<%=GetCurrentLoginUser().ID%>";

           $("#<%=FileUpload1.ClientID%>").uploadify(
           {
               "swf":"uploadify/uploadify.swf",
               "uploader":"UploadHandler.aspx",
               "auto":false,
               "method":"post",
               "multi":true,
               "buttonText":"浏览",
               "buttonImg":"uploadify/browse.jpg",
               "folder":"../uploadfile",
               "fileDesc":"附件",
               "onUploadStart":function(event,data){//thisiswhereyouwillsendtheform//data,butremembertogetiffrompostinthe.ashxfile,bycontex.Request["gallaryId"]
                   $("#<%=FileUpload1.ClientID%>").uploadify("settings","formData",
                         {"taskId":taskId,"activityId":activityId,"userId":userId,"secInfo":$("#<%=ddlsecInfo.ClientID%>").val()} //notehiddenGallaryIdwould//havethegallaryIdwhichimsendingthroughpost,makesureitisrenderedinyourpage(//i.e.notconcealedbyamultiviewcontrole.t.c)
            );
               }

           });
       });
   </script>
</head>
<body>
   <formid="form1"runat="server">
   <asp:FileUploadID="FileUpload1"runat="server"/>
   <asp:DropDownListID="ddlsecInfo"runat="server">
       <asp:ListItemText="公开"Value="1"></asp:ListItem>
       <asp:ListItemText="普通"Value="2"></asp:ListItem>
       <asp:ListItemText="机密"Value="3"></asp:ListItem>
   </asp:DropDownList>
   <ahref="javascript:$("#<%=FileUpload1.ClientID%>").uploadify("upload","*")">上传</a>
   <ahref="javascript:$("#<%=FileUpload1.ClientID%>").uploadify("cancel","*")">取消上传</a>
   </form>
</body>
</html>