0

I am trying to upload file on server using jquery and web handler. All works fine but issue is when i click on file upload control it pops up a file selection window, after i select file it directly started file uploading. My issue is i want upload file on different control's click event(i.e. On button click event).

Here is my code which i am currently working.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery-1.2.6.min.js" type="text/javascript"></script>
    <script src="jquery.ajax_upload.0.6.min.js" type="text/javascript"></script>
    <link href="default.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" language="javascript">
        $(document).ready(function () {

            var button = $('#fuAttachment'), interval;
            $.ajax_upload(button, {
                action: 'FileUploader.ashx',
                name: 'myfile',
                onSubmit: function (file, ext) {
                    if (ext == "jpg") {
                        return true;
                    }
                    else {
                        alert("Invalid File Type.");
                        return false;
                    }
                    //  this.disable();
                },
                onComplete: function (file, response) {
                    window.clearInterval(interval);
                    $('<li></li>').appendTo('.files').text(file);
                }
            });
        });
    </script>
</head>
<body>
<form>

<table border="0" width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td class="web_dialog_title">
                    <asp:Label ID="Label2" Text="Add Attachment" runat="server"></asp:Label>
                </td>
                <td class="web_dialog_title align_right">

                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblAtchTitle" runat="server" Text="Attachment :"></asp:Label>
                </td>
                <td>
                    <input type="file" id="fuAttachment" runat="server" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblAtchType" runat="server" Text="Type :"></asp:Label>
                </td>
                <td>
                    <select id="ddlAtchType" runat="server">
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblAttachDesc" runat="server" Text="Description :"></asp:Label>
                </td>
                <td>
                    <textarea id="txtAttachDesc" runat="server" cols="13" rows="4"></textarea>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    <table border="0" width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td>
                                <asp:Button ID="btnAddAttach" runat="server" Text="Attach" />
                                <input type="submit" runat="server" name="Submit" value="Submit" id="btnSub" />
                            </td>
                            <td>
                                <input type="reset" value="Reset" id="btnAttachReset" name="Reset" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <ol class="files">
                    </ol>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

I want my upload process should start on btnSub click event. If anyone knows than please help me.........

4

1 回答 1

0

你可以使用jquery uploadify

示例代码链接——下载

于 2012-06-29T10:29:37.673 回答