Pre-Upload Event

Last post 06-01-2011, 7:15 AM by linkbeto. 8 replies.
Sort Posts: Previous Next
  •  06-30-2008, 2:21 PM 41836

    Pre-Upload Event

    I need to validate other fields on the page before the file is actually uploaded. The problem is I have no access to the event which occurs when the user starts the upload process. This appears to all be handled in your dll. I would like to receive and event when the user attempts to start the upload, validate some other data on the page (like an email address or name field for example), then proceed with the upload if the other data checks out. If not, the file will not be uploaded.
  •  06-30-2008, 2:33 PM 41837 in reply to 41836

    Re: Pre-Upload Event

    OG1,
     
    Please use FileValidating.

     protected override void OnInit(EventArgs e)
      {
                base.OnInit(e);
                Uploader1.FileValidating+= new UploaderEventHandler(Uploader_FileValidating);       
      }


    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  06-30-2008, 4:04 PM 41846 in reply to 41837

    Re: Pre-Upload Event

    Thanks for the response. I tried this before posting but this event appears to fire after the file has already been uploaded, not before. I tested this by simply adding a breakpoint in the event and it fired after the progress reached 100%. I need the event to fire before any uploading occurs and also need the ability to cancel the upload from code.

  •  07-03-2008, 1:09 PM 41913 in reply to 41846

    Re: Pre-Upload Event

    Any word on this?
  •  07-07-2008, 1:54 AM 41969 in reply to 41836

    Re: Pre-Upload Event

    Hi,
     
     
    We have made some research on your request.
     
    We recommand you implement your request by this way:
     
    Use custom UI button by setting the Uploader1.InsertButtonID="AnotherButton"
     
    then the uploader script would replace the AnotherButton.onclick=..
     
    You can replace it by this way :
     
     
     
    <%@ Page Language="C#" %>
    <%@ Register TagPrefix="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" Namespace="CuteWebUI" %>
    <!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>Yes..</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                Email :
                <asp:TextBox ID="TextBox1" runat="server" />
                <br />
                <asp:Button ID="Button1" runat="server" Text="Start Upload.." />
                <CuteWebUI:Uploader runat="server" ID="Uploader1" InsertButtonID="Button1">
                </CuteWebUI:Uploader>
            </div>
        </form>
        <script>
       
        var inp1=document.getElementById('<%=TextBox1.ClientID %>');
        var btn1=document.getElementById('<%=Button1.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>
    </body>
    </html>
     
     
    Regards , Terry .
     
     
  •  07-07-2008, 9:32 AM 41979 in reply to 41969

    Re: Pre-Upload Event

    Thanks for the workaround. I will implement this and let you know if I have any problems.
     
    Thanks again
  •  06-01-2011, 12:04 AM 67755 in reply to 41969

    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.
  •  06-01-2011, 12:34 AM 67756 in reply to 67755

    Re: Pre-Upload Event

    Hi linkebte,
     
    Please try the example below
     
    <%@ Page Language="C#" %>

    <!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>example</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <table>
                <tr>
                    <td>
                     Email:
                    </td>
                    <td>
                     
                        <input id="text1" />
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <CuteWebUI:Uploader ID="Uploader1" runat="server" >
                        </CuteWebUI:Uploader>
                    </td>
                </tr>
            </table>
        </form>
    </body>
    </html>

    <script type="text/javascript">
    var uploader1=document.getElementById('<%=Uploader1.ClientID%>')
    var text1=document.getElementById("text1");
    uploader1.handlebrowse=function()
    {
      if (text1.value.indexOf("@") == -1) {
                alert("Please input your email!");
                return false;
     }
    }
    </script>
     
    Regards,
     
    ken
  •  06-01-2011, 7:15 AM 67761 in reply to 67756

    Re: Pre-Upload Event

    Thanks Kenneth, worked perfectly!
     
    Regards,
     
    Linkbeto
View as RSS news feed in XML