Getting filename from OnClientFileSelected and/or OnClientFileUploaded

8 posts, 0 answers
  1. Helmut
    Helmut avatar
    6 posts
    Member since:
    Feb 2014

    Posted 25 Mar 2014 Link to this post

    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.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Mar 2014 in reply to Helmut Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Helmut
    Helmut avatar
    6 posts
    Member since:
    Feb 2014

    Posted 27 Mar 2014 in reply to Shinu Link to this post

    Shinu,

        The alert showed the filename, but how do I retrieve it into my c# code so I can process it?  Thanks again!
  5. Helmut
    Helmut avatar
    6 posts
    Member since:
    Feb 2014

    Posted 27 Mar 2014 in reply to Helmut Link to this post

    I think I got it using a hidden JS field.  Thanks!
  6. Helmut
    Helmut avatar
    6 posts
    Member since:
    Feb 2014

    Posted 30 Mar 2014 in reply to Helmut Link to this post

    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#.
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Mar 2014 in reply to Helmut Link to this post

    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.
  8. Helmut
    Helmut avatar
    6 posts
    Member since:
    Feb 2014

    Posted 01 Apr 2014 in reply to Shinu Link to this post

    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.











  9. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Apr 2014 in reply to Helmut Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017