Validate field and upload

5 posts, 1 answers
  1. Merin
    Merin avatar
    14 posts
    Member since:
    Jul 2013

    Posted 28 Oct 2013 Link to this post

    Here is the scenario. There is a raddropdownlist and an asyncupload. The user should select an item (file type) from the drop down and this is a required field. I want to validate this field whenever the user attempt to upload a file. That is if the user didn't choose any file type and attempt to click the Select button, asyncupload should not open the File Select dialog. Instead it should validate the raddropdownlist which is the required field.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Oct 2013 Link to this post

    Hi Merin,

    Please have a look into the following code I tried which works fine at my end.

    ASPX:
    <telerik:RadDropDownList ID="RadDropDownList1" runat="server" DefaultMessage="Select File Type">
        <Items>
            <telerik:DropDownListItem runat="server" Text="JPG" />
            <telerik:DropDownListItem runat="server" Text="DOC" />
            <telerik:DropDownListItem runat="server" Text="PDF" />
        </Items>
    </telerik:RadDropDownList>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="RadDropDownList1"
        ForeColor="Red" ErrorMessage="*"></asp:RequiredFieldValidator>
    <br />
    <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" MultipleFileSelection="Automatic" />

    JavaScript:
    <script type="text/javascript">
        function pageLoad() {
            var $ = $telerik.$;
            $(".ruFileInput").click(function myfunction(e) {
                if (!Page_ClientValidate()) {
                    e.stopPropagation();
                    e.preventDefault();
                }
            });
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Merin
    Merin avatar
    14 posts
    Member since:
    Jul 2013

    Posted 01 Nov 2013 Link to this post

    Hi Shinu,

    Noticed an issue now. The code is working properly in my local machine but the exact code does not work in IE9 in Windows server 2008. I didn't made any change but the validation is not firing and the dialog is opening to select the files. Any configuration needed in the server?
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Nov 2013 Link to this post

    Hi Merin,

    You don't need any configuration settings in the server as this issue is related to the upload module being used in the respective browser. Please have in mind that such validation can not be achieved when RadAsyncUpload uses Silverlight upload module. In IE-9, the default upload module used is Silverlight and that is why the validation is not working. In your local machine you may be using a later version of IE such as IE-10 which uses FileApi and this works.

    You can use the following client side code to disable Silverlight module.

    JavaScript:
    <script type="text/javascript">
        Telerik.Web.UI.RadAsyncUpload.Modules.Silverlight.isAvailable = function () { return false; }
        function pageLoad() {
            var $ = $telerik.$;
            $(".ruFileInput").click(function myfunction(e) {
                if (!Page_ClientValidate()) {
                    e.stopPropagation();
                    e.preventDefault();
                }
            });
        }
    </script>

    Thanks,
    Shinu.
  6. Merin
    Merin avatar
    14 posts
    Member since:
    Jul 2013

    Posted 03 Nov 2013 Link to this post

    Hi Shinu,

    Thank you for the quick valuable support and now the issue is resolved. You guessed it correctly, my local machine is running IE10. :)

    Regards,
    Merin
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017