欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net使用jQuery Uploadify上传附件示例

程序员文章站 2024-02-25 23:01:39
uploadify是jquery的一个上传插件,实现的效果非常不错,带进度显示。uploadify官方网址:,在mvc中使用的方法可以参考 jquery uploadify...

uploadify是jquery的一个上传插件,实现的效果非常不错,带进度显示。uploadify官方网址:,在mvc中使用的方法可以参考 jquery uploadify在asp.net mvc3中的使用 和 asp.net mvc中使用uploadify实现图片缩放保存。

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

复制代码 代码如下:

<!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>
    <link href="uploadify/uploadify.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="uploadify/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="uploadify/swfobject.js"></script>
    <script type="text/javascript" src="uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript">

        $(function () {
            var taskid = "<%= taskid %>";
            var activityid = "<%= activityid %>";
            var userid = "<%= 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) { //this is where you will send the form //data, but remember to get if from post in the .ashx file, by contex.request["gallaryid"]
                    $("#<%=fileupload1.clientid %>").uploadify('settings', 'formdata',
                          { 'taskid': taskid, 'activityid': activityid, 'userid': userid, 'secinfo': $("#<%=ddlsecinfo.clientid %>").val()}  //note hiddengallaryid would //have the gallaryid which im sending through post , make sure it is rendered in your page( //i.e.not concealed by a multiview control e.t.c)
             );
                }

            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:fileupload id="fileupload1" runat="server" />
    <asp:dropdownlist id="ddlsecinfo" runat="server">
        <asp:listitem text="公开" value="1"> </asp:listitem>
        <asp:listitem text="普通" value="2"> </asp:listitem>
        <asp:listitem text="机密" value="3"> </asp:listitem>
    </asp:dropdownlist>
    <a href="javascript: $('#<%=fileupload1.clientid %>').uploadify('upload','*')">上传</a>
    <a href="javascript:$('#<%=fileupload1.clientid %>').uploadify('cancel','*')">取消上传</a>
    </form>
</body>
</html>