asp. net USES jQuery Uploadify to upload sample attachments

  • 2020-10-07 18:37:50
  • OfStack

Uploadify is one of the upload plug-ins of JQuery, and the effect is very good, with progress display. Uploadify official website: http: / / www uploadify. com /, in MVC method can be used in the reference jQuery Uploadify in ASP. NET MVC3 in use and Asp net Mvc use uploadify implement zooming in preservation.

This article is a simple introduction to Demo, mainly the dynamic parameter passing method: pass additional form data to the handler through 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': ' browse ',
                'buttonImg': 'uploadify/browse.jpg',
                'folder': '../uploadfile',
                'fileDesc': ' The attachment ',
                '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=" public " Value="1"> </asp:ListItem>
        <asp:ListItem Text=" ordinary " Value="2"> </asp:ListItem>
        <asp:ListItem Text=" confidential " Value="3"> </asp:ListItem>
    </asp:DropDownList>
    <a href="javascript: $('#<%=FileUpload1.ClientID %>').uploadify('upload','*')"> upload </a>
    <a href="javascript:$('#<%=FileUpload1.ClientID %>').uploadify('cancel','*')"> Cancel the upload </a>
    </form>
</body>
</html>


Related articles: