Re: Using UploadPersistedFile and making file upload mandatory

  •  10-18-2011, 8:35 AM

    Re: Using UploadPersistedFile and making file upload mandatory

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

    <%@ Register Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" TagPrefix="CuteWebUI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

        protected void uploader1_UploadCompleted(object sender, UploaderEventArgs[] args)
        {
            hf1.Value = args.Length.ToString();
        }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <CuteWebUI:UploadPersistedFile ID="uploader1" runat="server" OnUploadCompleted="uploader1_UploadCompleted">
            </CuteWebUI:UploadPersistedFile>
            <asp:HiddenField ID="hf1" runat="server" />
            <asp:Button ID="btnSubmit" runat="server" OnClientClick="return verify()" Text="submit" />
        </form>
    </body>
    </html>

    <script type="text/javascript">

    function verify()
    {
        var hf1=document.getElementById("<%=hf1.ClientID %>");
        if(hf1.value=="")
        {
            alert("please upload a file before submit");
            return false;
        }
        return true;
       
    }
    </script>
     
    Regards,
     
    Ken
View Complete Thread