Set description field to uploaded filename

Thread is closed for posting
2 posts, 0 answers
  1. Mark
    Mark avatar
    5 posts
    Member since:
    Oct 2011

    Posted 15 Nov 2011 Link to this post

    I had a requirement to set my description field to the uploaded filename. I used the additional field example supplied by Telerik.
    Here is how I set that value:

    <telerik:radupload id="RadUpload1" runat="server" onclientadded="addTitle" onclientfileselected="uploadFileSelected" />

    <script type="text/javascript" language="javascript">
        function uploadFileSelected(sender, args) {
            var currentIndex = sender._currentIndex - 1;
            fileNameTextBox = $get('<%= RadUpload1.ClientID %>' + 'Desc' + currentIndex);
            var inputValue = args.get_fileInputField().value;
            var fileName = inputValue.substring(inputValue.lastIndexOf("\\") + 1);

            fileNameTextBox.value = fileName;

        function addTitle(radUpload, args) {
            var curLiEl = args.get_row();
            var firstInput = curLiEl.getElementsByTagName("input")[0];

            //Create a simple HTML template.
            var table = document.createElement("table");
            table.className = 'AdditionalInputs';

            //A new row for a Title field
            row = table.insertRow(-1);
            cell = row.insertCell(-1);
            var input = CreateInput("Title", "text");
            input.className = "TextField";
   = = radUpload.getID(;
            var label = CreateLabel("Title",;
            cell = row.insertCell(-1);

            //A new row for a Description field
            row = table.insertRow(-1);
            cell = row.insertCell(-1);

            input = CreateInput("Desc", "text");
            input.className = "TextField";
   = = radUpload.getID(;
            label = CreateLabel("Description",;
            //label.innerHTML = firstInput.valueOf;
            cell = row.insertCell(-1);

            //Add a File label in front of the file input
            var fileInputSpan = curLiEl.getElementsByTagName("span")[0];
            var firstNode = curLiEl.childNodes[0];
            label = CreateLabel("File", radUpload.getID());
            curLiEl.insertBefore(label, firstNode);

            curLiEl.insertBefore(table, label);

  2. Peter Filipov
    Peter Filipov avatar
    1028 posts

    Posted 16 Nov 2011 Link to this post

    Hi Leroy,

    I wasn't able to run your sample code.
    My suggestion is to find the text box with jQuery and set the value you want. E.g. you can access the li element that contains the additional fields and the input type='file'.

    To avoid duplication of the the thread please continue the discussion in only one of them.

    Peter Filipov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top