Re: Pre-Upload Event

  •  06-01-2011, 12:04 AM

    Re: Pre-Upload Event

    Hi,
     
    I'm testing ajaxuploader and facing same issue. My code is not working, the dialog box to select a file still open on click button. Could you help me please?
     
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm2.aspx.vb" Inherits=".WebForm2" %>
    <%@ Register assembly="CuteWebUI.AjaxUploader" namespace="CuteWebUI" tagprefix="cc1" %>
    <!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>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
            <asp:Button ID="btUpload" runat="server" Text="Fazer Upload" />
            <cc1:Uploader ID="Uploader" runat="server" OnFileUploaded="SalvarArquivo" InsertButtonID="btUpload"
                CancelText="Cancelar" InsertText="Selecione o arquivo">
            </cc1:Uploader>
        </div>
        </form>
        </body>
    </html>
    <script type="text/javascript">
        var inp1 = document.getElementById('<%=txtEmail.ClientID %>');
        var btn1 = document.getElementById('<%=btUpload.ClientID %>');
       
        var int1;
        function MyClickHandler(event) {
            if (inp1.value.indexOf("@") == -1) {
                alert("Please input your email!");
                inp1.focus();
            }
            else {
                //Email OK! call the uploader script to browser the file and upload..
                btn1.uploaderclick();
            }
            //always cancel the onclick event, otherwise the form would do the postback!
            event = window.event || event;
            if (event.preventDefault) event.preventDefault();
            return event.returnValue = false;
        }
        function CheckUploaderScriptStatus() {
            //if the uploader script be loaded , the btn1.onclick would be setted
            //then you can replace it :
            if (btn1.onclick) {
                //stop the interval timer
                clearInterval(int1);
                //save the uploader handler
                btn1.uploaderclick = btn1.onclick;
                //use my own handler
                btn1.onclick = MyClickHandler;
            }
        }
        int1 = setInterval(CheckUploaderScriptStatus, 10);
    </script>
    Regards, Carlos.
View Complete Thread