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

Getting filename from OnClientFileSelected and/or OnClientFileUploaded

7 Answers 323 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Helmut
Top achievements
Rank 1
Helmut asked on 25 Mar 2014, 04:51 PM
Are there any quick JS examples of how I can get the filename values through these functions so I can process them further in my C# code?  I need to be able to retrieve them and add them to a SQL repository of associated data.  Pretty elementary, but I'm still learning JS.  Thank you.

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Mar 2014, 02:47 AM
Hi Helmut,

Please try the following JavaScript code snippet to get the file name in OnClientFileSelected and OnClientFileUploaded event.

JavaScript:
<script type="text/javascript">
    function OnClientFileSelected(sender, args) {
        alert(args.get_fileName());
    }
    function OnClientFileUploaded(sender, args) {
        alert(args.get_fileName());
    }
</script>

Thanks,
Shinu.
0
Helmut
Top achievements
Rank 1
answered on 27 Mar 2014, 06:49 PM
Shinu,

    The alert showed the filename, but how do I retrieve it into my c# code so I can process it?  Thanks again!
0
Helmut
Top achievements
Rank 1
answered on 27 Mar 2014, 09:09 PM
I think I got it using a hidden JS field.  Thanks!
0
Helmut
Top achievements
Rank 1
answered on 30 Mar 2014, 08:09 PM
Maybe I spoke too quickly.  I can see the value within the JS code, but it's coming up as blank when I try to access it via c#.
0
Shinu
Top achievements
Rank 2
answered on 31 Mar 2014, 04:49 AM
Hi Helmut,

Please try the following sample code snippet which works fine at my end.

ASP:
<telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" OnClientFileUploaded="OnClientFileUploaded">
</telerik:RadAsyncUpload>
<asp:HiddenField ID="HiddenField1" runat="server" />
<telerik:RadButton ID="RadButton1" runat="server" Text="FileName" OnClick="RadButton1_Click">
</telerik:RadButton>

JavaScript:
<script type="text/javascript">
    function OnClientFileUploaded(sender, args) {
        alert(args.get_fileName());
        var hiddenfield = document.getElementById("HiddenField1");
        hiddenfield.value = args.get_fileName();
    }
</script>

C#:
protected void RadButton1_Click(object sender, EventArgs e)
{
    string filename = HiddenField1.Value;
}

Please elaborate your requirement if it doesn't help.
Thanks,
Shinu.
0
Helmut
Top achievements
Rank 1
answered on 01 Apr 2014, 04:58 PM
Shinu, 

   Please see the attached screenshot that is appearing when I hit the "Submit" button on my form.  The upload progress shows that the file uploaded, but then I get the attached error.  My scenario.

1.  User answers form header and form detail questions.  At any time they can save their progress which will generate a unique grant ID. 
2.  There are 4 required files that need to be uploaded via 4 RadAsync upload controls.  I want to get the name of the file they uploaded and assign it a file ID into a repository table in SQL server along with some other data.











0
Shinu
Top achievements
Rank 2
answered on 02 Apr 2014, 04:36 AM
Hi Helmut,

From your code I noticed that you are using 'document.getElementByID' method for accessing the hidden field. There is no such method is existing in JavaScript. Please try to change the method to 'document.getElementById' which works as expected for me. Please have a look into the sample code snippet.

ASPX:
<telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" OnClientFileUploaded="OnClientFileUploaded">
</telerik:RadAsyncUpload>
<telerik:RadAsyncUpload ID="RadAsyncUpload2" runat="server" OnClientFileUploaded="OnClientFileUploaded1">
</telerik:RadAsyncUpload>
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:HiddenField ID="HiddenField2" runat="server" />
<telerik:RadButton ID="RadButton1" runat="server" Text="FileName" OnClick="RadButton1_Click">
</telerik:RadButton>

JavaScript:
<script type="text/javascript">
    function OnClientFileUploaded(sender, args) {
        var hiddenfield = document.getElementById("HiddenField1");
        hiddenfield.value = args.get_fileName();
    }
    function OnClientFileUploaded1(sender, args) {
        var hiddenfield = document.getElementById("HiddenField2");
        hiddenfield.value = args.get_fileName();
    }
</script>

C#:
protected void RadButton1_Click(object sender, EventArgs e)
{
    string filename1 = HiddenField1.Value;
    string filename2 = HiddenField2.Value;
}

Thanks,
Shinu.
Tags
AsyncUpload
Asked by
Helmut
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Helmut
Top achievements
Rank 1
Share this question
or