This is a migrated thread and some comments may be shown as answers.

OnClientFileSelected not firing?

9 Answers 192 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
dmc_lat47
Top achievements
Rank 1
dmc_lat47 asked on 27 Aug 2008, 06:16 PM
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

9 Answers, 1 is accepted

Sort by
0
Erjan Gavalji
Telerik team
answered on 28 Aug 2008, 08:41 AM
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.
0
dmc_lat47
Top achievements
Rank 1
answered on 28 Aug 2008, 05:55 PM
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
0
Erjan Gavalji
Telerik team
answered on 29 Aug 2008, 06:02 AM
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.
0
dmc_lat47
Top achievements
Rank 1
answered on 30 Aug 2008, 11:57 PM
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

0
Veselin Vasilev
Telerik team
answered on 01 Sep 2008, 03:32 PM
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.
0
dmc_lat47
Top achievements
Rank 1
answered on 01 Sep 2008, 10:00 PM
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
0
Veselin Vasilev
Telerik team
answered on 04 Sep 2008, 01:02 PM
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.
0
Prassin
Top achievements
Rank 1
answered on 27 Jul 2012, 05:35 AM
Hi All,

How can i get this OnClientFileSelected event at Code Behind?

Please replay...

Regards,

Prassin
0
Princy
Top achievements
Rank 2
answered on 27 Jul 2012, 06:30 AM
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.
Tags
Upload (Obsolete)
Asked by
dmc_lat47
Top achievements
Rank 1
Answers by
Erjan Gavalji
Telerik team
dmc_lat47
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Prassin
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or