OnClientFileSelected not firing?

Thread is closed for posting
10 posts, 0 answers
  1. dmc_lat47
    dmc_lat47 avatar
    6 posts
    Member since:
    Jan 2007

    Posted 27 Aug 2008 Link to this post

    Hi all...
    this is probably a really basic question...

    what i'm trying to do is to validate whether the user has specified any files to be uploaded.  I'm using just a single text box and a browse button.

    I figured on using OnClientFileSelected to go to a function which will see if the file input string is zero length.

    However, the event doesn't seem to be firing.  Here is the RadUpload declaration:

    <telerik:RadUpload InputSize="40" Width="300" ID="RadUpload1" runat="server"

    ControlObjectsVisibility="None" OnClientFileSelected="checkInputFilePath" />

    <telerik:RadProgressArea ID="progressArea1" runat="server" Skin="" />

    The function looks like this:

    function checkInputFilePath(radUpload, eventArgs)

        {

            alert(

    'here we are');

        }

    The alert never happens, though an alert downstream of this, in another function, does.
    Anything additionally have to be set?

    Thanks in advance
    david

  2. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 28 Aug 2008 Link to this post

    Hi dmc_lat47,

    Do you type the invalid name to the file input field? In this case, alert should happen when the control looses the focus. FYI, we had some small problems with the file input skinning model of RadUpload in RadControls for ASP.NET Ajax version 2008.2 723. Please, download the latest version (released several days ago) and give it a try.

    Kind regards,
    Erjan Gavalji
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. dmc_lat47
    dmc_lat47 avatar
    6 posts
    Member since:
    Jan 2007

    Posted 28 Aug 2008 Link to this post

    what happens if I only want to check if the input text is zero length?  that is, when someone hits 'submit' but has forgotten to specify a file to upload?

    I did upload the new controls, and see the same behavior.

    Maybe this isn't the way I should check for a "no-input" error condition?

    thanks in advance
    david
  5. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 29 Aug 2008 Link to this post

    Hi dmc_lat47,

    Please, check the RadUpload Client-Side Validation example. You can walk the RadUpload's file inputs and check if they are empty in the client-side validation function.

    Let me know if that helps.

    All the best,
    Erjan Gavalji
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. dmc_lat47
    dmc_lat47 avatar
    6 posts
    Member since:
    Jan 2007

    Posted 30 Aug 2008 Link to this post

    I think I'm missing something...

    I took a look at the example you cited, and I think the relevant line is:

    arguments.IsValid = getRadUpload('<%= RadUpload1.ClientID %>').validateExtensions();

    And I looked in the documentation for the control, and found the radUpload.validateExtensions() function documentation.

    However, I wasn't able to find a radUpload.FileInputIsZero() function, so I think I'm not understanding you.

    thank you for your help

    david

  7. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 01 Sep 2008 Link to this post

    Hello dmc_lat47,

    Can you please clarify where did you see the FileInputIsZero in our documentation?

    Thanks

    All the best,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. dmc_lat47
    dmc_lat47 avatar
    6 posts
    Member since:
    Jan 2007

    Posted 01 Sep 2008 Link to this post

    um..
    sorry for the confusion. I did not see a "FileInputIsZero" in the documentation, that is what *i would like* to find...

    to be clearer... i'm looking for some functionality that would tell me when the file specification entered by the user was zero length.  The check I'm trying to make is if the user, for instance, forgot to specify a file to upload and hit submit.

    I looked at the example cited, and could not figure out how to do this.

    thanks
    david
  9. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 04 Sep 2008 Link to this post

    Hello dmc_lat47,

    Please consider this example:

    <telerik:RadUpload ID="RadUpload1" runat="server"
    </telerik:RadUpload>        
    <asp:Button ID="Button1"  
       runat="server"  
       Text="Button"  
       OnClientClick="return validateUpload()" /> 


    <script type="text/javascript"
        function validateUpload() { 
            var upload = $find("<%= RadUpload1.ClientID %>"); 
            var fileInputs = upload.getFileInputs(); 
             
            for (var i = 0; i < fileInputs.length; i++) { 
                if (fileInputs[i].value != "") { 
                    return true
                } 
            } 
            alert("Please Select at least one file"); 
            return false
        } 
    </script>  

    Please test it and let me know if it is ok for you.

    Regards,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  10. Prassin
    Prassin avatar
    87 posts
    Member since:
    Jun 2012

    Posted 27 Jul 2012 Link to this post

    Hi All,

    How can i get this OnClientFileSelected event at Code Behind?

    Please replay...

    Regards,

    Prassin
  11. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 Jul 2012 Link to this post

    Hi Prassin,

    I suppose you want to fire a serverside event when a file is selected in RadUpload. One suggestion is that you can add a Button and attach the click event to that Button inside the OnClientFileSelected event as follows.

    CSS:
    <style type="text/css">
      .display
        {
            display:none;
        }
    </style>

    ASPX:
    <telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
      <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="Button1">
          <UpdatedControls>
             <telerik:AjaxUpdatedControl ControlID="Button1" />
          </UpdatedControls>
        </telerik:AjaxSetting>
      </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadUpload ID="RadUpload1" runat="server" OnClientFileSelected="OnClientFileSelected" ></telerik:RadUpload>
    <asp:Button ID="Button1" runat="server" CssClass="display" OnClick="Button1_Click"/>

    JS:
    <script type="text/javascript">
        function OnClientFileSelected(sender, args) {
            var btn = document.getElementById("Button1");
            btn.click();
        }
    </script>

    C#:
    protected void Button1_Click(object sender, EventArgs e)
     {
       //Your Code for file selected
     }

    Hope this helps.

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