简体   繁体   中英

How to get the value of the textbox which created dynamically with the Raduploader in code behind?

I use the AsyncUpload


 <telerik:RadAsyncUpload runat="server" ID="rada_attach" OnClientFileUploaded="onClientFileUploaded"
                                MultipleFileSelection="Disabled" InitialFileInputsCount="1" MaxFileInputsCount="1"
                                Width="100%" />

function onClientFileUploaded(radAsyncUpload, args) {
    var row = args.get_row(),
        inputName = radAsyncUpload.getAdditionalFieldID("TextBox"),
        inputType = "text",
        inputID = inputName,
        input = createInput(inputType, inputID, inputName),
        label = createLabel(inputID),
        br = document.createElement("br");

    row.appendChild(br);
    row.appendChild(input);
    row.appendChild(label);

}

function createInput(inputType, inputID, inputName) {
    var input = document.createElement("input");

    input.setAttribute("type", inputType);
    input.setAttribute("id", inputID);
    input.setAttribute("name", inputName);

    return input;
}

I want to access the textbox (which created dynamically) in .cs.

How to do that ?


The Full Answer :

var $ = $telerik.$;

function onClientFileUploaded(radAsyncUpload, args) {
    var $row = $(args.get_row());
    var inputName = radAsyncUpload.getID("TextBox");
    var inputType = "text";
    var inputID = inputName;
    var input = createInput(inputType, inputID, inputName);
    var label = createLabel(inputID);
    $row.append("<br/>");
    $row.append(label);
    $row.append(input);
}

function createInput(inputType, inputID, inputName) {
    var input = '<input type="' + inputType + '" id="' + inputID + '" name="' + inputName + '" />';
    return input;
}

function createLabel(forArrt) {
    var label = '<label for=' + forArrt + '>info: </label>';
    return label;
}

   foreach (UploadedFile UF in rada_attach.UploadedFiles)
                {
                    if (UF.GetFieldValue("TextBox") != null)
                    {
                        OBJ.File_name = UF.GetFieldValue("TextBox");
                    }
                    else
                    {
                        OBJ.File_name = UF.GetName();
                    }

In my opinion documentation is well clear. Check the Description tab on page you refer on. You can access value of dynamic textboxes with code below on postback:

if (rada_attach.UploadedFiles.Count > 0) {
    for (var index = 0; index < rada_attach.UploadedFiles.Count; ++index) {
        var textBoxValue = rada_attach.UploadedFiles[index].GetFieldValue("TextBox");
    }
}

BTW, this scenario is well-dcoumented here: Adding Information to Uploaded Files

You need to check the Request.Form values (that were in the posted form) on postback and perform a check on all the fields that were posted back.

I am guessing that you won't know the name/id of the textbox if it was created on the client-side dynamically? Note that it would be the name of the form field that the Request object in .cs would see.

Only once you have posted back can you access that value in the .cs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM