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

when click each time add button in radupload I want two textbox

27 Answers 285 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Priya Priya
Top achievements
Rank 1
Priya Priya asked on 20 Oct 2009, 07:39 AM
hi!
        In radupload control, when press add button , just fileinput box only appear... when click each time add button in radupload,  I want two textbox also....can anyone help me?..thanks

27 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Oct 2009, 06:46 AM
Hi Priya,

I tried following code snippet in order to add two upload textboxes when clicking the Add button.

JavaScript:
 
<script type="text/javascript"
    var check = 0; 
    function OnClientAdded(sender, args) { 
        if (args.get_rowIndex() != 0 && check == 0) { 
            check = 1; 
            sender.addFileInput(); 
        } 
        else { 
            check = 0; 
        } 
    } 
</script> 

-Shinu.
0
Priya Priya
Top achievements
Rank 1
answered on 21 Oct 2009, 08:24 AM
HI!

       thanks...I used below script..

 

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";

 

input.id = input.name = radUpload.getID(input.name);

 

var label = CreateLabel("Name",input.id);

 

cell.appendChild(label);

cell = row.insertCell(-1);

cell.appendChild(input);

 

 

//A new row for a Description field

 

row = table.insertRow(-1);

cell = row.insertCell(-1);

 

input = CreateInput(

"Desc", "text");

 

input.className =

"TextField";

 

input.id = input.name = radUpload.getID(input.name);

label = CreateLabel(

"Type of the Document",input.id);

 

cell.appendChild(label);

cell = row.insertCell(-1);

cell.appendChild(input);

 

 

 

//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);

}

 

 

function CreateLabel(text, associatedControlId)

 

{

 

var label = document.createElement("label");

 

label.innerHTML = text;

label.setAttribute(

"for", associatedControlId);

 

label.style.fontSize = 12;

 

 

return label;

 

}

 

 

function CreateInput(inputName, type)

 

{

 

var input = document.createElement("input");

 

input.type = type;

input.name = inputName;

 

 

return input;

 

}


how i can  retrive these description & title textbox value to database....please help me?

0
Genady Sergeev
Telerik team
answered on 22 Oct 2009, 03:13 PM
Hello Priya Priya,

On the server, you can access the additional fields in the following way:

protected void Button1_Click(object sender, EventArgs e)
{
 foreach (UploadedFile f in RadUpload1.UploadedFiles)
 {
   string fileName = f.GetName();
   string title = f.GetFieldValue("Title");
   string desc = f.GetIsFieldChecked("Desc");
   // Proceed with your database insertion
 }
}

Since you have the values in the variables title and desc you can proceed with the database insertion. The insertion depends on what access layer you use.

Best wishes,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Priya Priya
Top achievements
Rank 1
answered on 23 Oct 2009, 08:34 AM
hi!

        thank you! I have another one issue....I have create two textbox using above script...I want these two textbox and rad upload in a single row....can anyone give sample code?

thanks!
0
Genady Sergeev
Telerik team
answered on 29 Oct 2009, 11:10 AM
Hello Priya Priya,

I have prepared example for you that shows hot to achieve the desired functionality. I have used jQuery instead of pure JavaScript with led to dramatically reduced code, just 3 lines of code. You can find the sample as an attachment.

Regards,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Priya Priya
Top achievements
Rank 1
answered on 30 Oct 2009, 06:22 AM
hi!

       thank u very much...I want label field also....how include label field in script?

thX...
0
Genady Sergeev
Telerik team
answered on 04 Nov 2009, 03:32 PM
Hello Priya Priya,

You can use the following modified code:

function onClientAddedHandler(sender, args)
        {
            var idAddField = sender.getID("additional");
            $(".ruInputs li[class='']:last span")
                .before($("<label>Type of the Document</label>").attr("for", idAddField))
                .before($("<input type='text' />").attr( "id", idAddField ).attr("name", idAddField));
        }


All the best,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Priya Priya
Top achievements
Rank 1
answered on 09 Nov 2009, 10:59 AM
hi! thank u very much...
0
Nikesh Bhagat
Top achievements
Rank 1
answered on 18 Nov 2009, 02:42 AM
How would I go about validating the checkboxes I've added to my radupload via Priya Priya's first method so that only 1 of them can be checked at a time?
0
Sebastien Desemberg
Top achievements
Rank 1
answered on 04 Dec 2009, 11:56 AM
Hi,

I want to add textboxes, just like the upload does, but , not for uploading files. I just want to add textboxes,that will be bound to the database. How best can I achieve this.

Regards,
0
Shinu
Top achievements
Rank 2
answered on 09 Dec 2009, 11:29 AM
Hello Sebastian,

I guess you want to add textboxes dynamically on clicking a button. Here is the code snippet which I tried for accomplishing the scenario.

ASPX:
 
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server"
         <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />        
</telerik:RadAjaxPanel>  

CS:
 
protected void Page_Load(object sender, EventArgs e) 
    { 
        if (IsPostBack) 
        { 
            if (ViewState["Index"] != null
            { 
                int index = Convert.ToInt32(ViewState["Index"]); 
 
                if (getPostBackControlName() == "Button1"
                { 
                    for (int i = 0; i <= index; i++) 
                    { 
                        TextBox txtbx = new TextBox(); 
                        txtbx.ID = "TextBox" + i; 
                        RadAjaxPanel1.Controls.Add(txtbx); 
                    } 
                } 
                else 
                { 
                    for (int i = 1; i <= index; i++) 
                    { 
                        TextBox txtbx = new TextBox(); 
                        txtbx.ID = "TextBox" + i; 
                        RadAjaxPanel1.Controls.Add(txtbx); 
                    } 
                } 
            } 
        } 
        else 
        { 
            ViewState["Index"] = 0; 
        } 
    } 
    protected void Button1_Click(object sender, EventArgs e) 
    {         
        if (ViewState["Index"] == null
        { 
            TextBox txtbx = new TextBox(); 
            txtbx.ID = "TextBox1"
            RadAjaxPanel1.Controls.Add(txtbx); 
        } 
        ViewState["Index"] = Convert.ToInt32(ViewState["Index"]) + 1; 
    } 
 
    private string getPostBackControlName() 
    { 
 
        Control control = null
        string ctrlname = Page.Request.Params["__EVENTTARGET"]; 
 
        if (ctrlname != null && ctrlname != String.Empty) 
        { 
            control = Page.FindControl(ctrlname); 
        } 
        // if __EVENTTARGET is null, the control is a button type and we need to 
        // iterate over the form collection to find it 
        else 
        { 
            string ctrlStr = String.Empty; 
 
            Control c = null
 
            foreach (string ctl in Page.Request.Form) 
            { 
                if (ctl.EndsWith(".x") || ctl.EndsWith(".y")) 
                { 
                    ctrlStr = ctl.Substring(0, ctl.Length - 2); 
                    c = Page.FindControl(ctrlStr); 
                } 
                else 
                { 
                    c = Page.FindControl(ctl); 
                } 
                if (c is System.Web.UI.WebControls.Button || c is System.Web.UI.WebControls.ImageButton) 
                { 
                    control = c; 
                    break
                } 
            } 
        } 
        return control.ID; 
    }  

Hope this helps,
Shinu.
0
Genady Sergeev
Telerik team
answered on 10 Dec 2009, 09:57 AM
Hi guys,

Nikesh Bhagat, concern using RadioButtons instead of CheckBoxes. They suit your case far more good. You can find out how to do it in this thread.

Sebastien Desemberg, I am not sure what you are trying to achieve. The code that I have posted shows how to add textboxes to RadUpload in order to have additional fields containing information regarding the files uploaded.

In order to have TextBoxes bound to a database fields, you need to use a DataBound control. There are other ways as well but they are more complicate. Choosing the control that suits your needs best depends on how much information you need to extract. If you supply us with more information regarding your scenario we will provide you with tips and suggestions on how to achieve your task. 

Regards

Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Sebastien Desemberg
Top achievements
Rank 1
answered on 10 Dec 2009, 10:16 AM
@Shinu, thanks, just what I wanted.
0
Nikesh Bhagat
Top achievements
Rank 1
answered on 11 Dec 2009, 10:03 AM
Hey Genady,

I took a look at the thread you recommended, but it's not quite what i'm looking for.  The thread describes how to create a radiobutton list for each addtional RadUpload input element so that you can only select one or the other radiobutton option, but for each input field.  In other words, more than one radiobutton can be selected if there is more than one input field added by the user...

I want to be able to add a radiobutton list to the entire input field collection so that you can only select one radiobutton in total..

For Example: The user adds two input fields: input1 and input2.  Each input has a radiobutton attached to it, but the user is only able to select either input1 or input2, leaving one or the other unselected... and leaving me with only the value of the one and only selected radiobutton..  I would need to allow the user to clear the radiobutton list so no radiobutton is selected and I'm unsure of how I would iterate through the UploadedFiles in order to retrieve the value of a radiobutton if it is selected...

any ideas?

Nik
0
Genady Sergeev
Telerik team
answered on 14 Dec 2009, 03:48 PM
Hi Nikesh Bhagat,

 I have prepared sample project that demonstrates the mentioned functionality:

1) Each row has it's own radio button

2) Only one radio button can be selected at a time

3) You can obtain its value from the server the standard way. All radio buttons that are not selected will return NULL as their value. The selected one will return the value that you have set on the client.

You can find the project as an attachment.

Best wishes,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Nikesh Bhagat
Top achievements
Rank 1
answered on 14 Dec 2009, 07:47 PM
Hello Genady,

This is EXACTLY what I'm looking for... But when I plunked code into my project I got this error:

Assembly 'Telerik.Web.UI, Version=2008.1.515.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4' does not contain a Web resource with name 'Telerik.Web.UI.Common.jQuery.js'.


I understand the project reference jQuery... but I'm not sure how to implement this properly...

regards,

Nik



0
Genady Sergeev
Telerik team
answered on 17 Dec 2009, 09:21 AM
Hi Nikesh Bhagat,

Your version of the controls does not have jQuery, therefore the script references can't find it and error is thrown. Either upgrade to a newer version of the controls or add manually jQuery to your page. You can download jQuery from here.


All the best,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Nikesh Bhagat
Top achievements
Rank 1
answered on 16 Feb 2010, 10:03 PM
Hello,

So I've manually implemented jquery on my page as follows:

<script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>

But i'm getting an 'object expected' error starting from the following line as indicated by IE8:

var $radioButton = $("<input type='radio' />").attr("name", idAddField).val("Value1");

Any ideas?


0
bharti ten
Top achievements
Rank 1
answered on 19 Feb 2010, 04:57 AM
Hello telerik team,

I would appreciate so much if you can reply to me as early as possible.
I have added a "Title" custom text box to each instance of Radupload files using "onClientAdded" fucntion.

But, now i need to validate the additional text box added using java script, and
I have been trying so many ways in futile. Client side validation is mandatory

Please help me asap.

Thank you,
Bharathi
0
Genady Sergeev
Telerik team
answered on 19 Feb 2010, 02:33 PM
Hello guys,

bharti ten, I have attached sample project that demonstrates how to validate the additional file inputs.

Nikesh Bhagat, why are you insert jQuery manually? jQuery is used internally by almost all RadControls, therefore if you have, say RadUpload, on your page you automatically have jQuery as well. You can access the jQuery object using the following syntax:

var jQuery = $telerik.$;

Using the jQuery version that ships with RadControls I am unable to reproduce the issue that you experience. Can you open a support ticket and attach sample project that fails on your side? This will allow to track and debug the issue for you.



All the best,
Genady Sergeev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Nikesh Bhagat
Top achievements
Rank 1
answered on 19 Feb 2010, 08:46 PM
I'm implementing it manually because, as I mentioned in a previous post, I was getting this error:

Assembly 'Telerik.Web.UI, Version=2008.1.515.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4' does not contain a Web resource with name 'Telerik.Web.UI.Common.jQuery.js'.


You informed me that this was because my version of the controls do not include jQuery and instructed me to implement it manually since I am  unwilling to update my controls...




0
bharti ten
Top achievements
Rank 1
answered on 20 Feb 2010, 05:53 AM
Hello Telerik,

The $get("RadUpload1description" + i).value , doesn't work as intended, or I am doing some thing wrong.


   function validateInputs(sender, e) {
            e.IsValid = false;
            alert("hbv");
            var upload = $find('<%= RadUpload1.ClientID %>');
            var inputs = upload.getFileInputs();
            alert(inputs.length);
            for (var i = 1; i <= inputs.length; i++) {
                //check for empty string or invalid extension
                var descValue = $get("RadUpload1description" + i).value
                alert(descValue);
                alert("hh");

                if (inputs[i].value == "" || !upload.isExtensionValid(inputs[i].value)
                    || descValue == "") {
                   
                    e.IsValid = false;
                    return;
                }
            }
            e.IsValid = true;
        }
When i said alert(descValue) , its not doing anything, I mean even though i do not provide Description,
e.IsValid = true is being executed and hence not seeing any error message.

Please help at your earliest convenience.
 I am using ASP.Net ajax Rad controls, if this might help.
Thank you,
Bharathi
0
Genady Sergeev
Telerik team
answered on 23 Feb 2010, 02:03 PM
Hi bharti ten,

Please replace

var descValue = $get("RadUpload1description" + i).value

with

var descValue = $get('<%= RadUpload1.ClientID %>' + 'description' + i).value;

Does the issue persist?

Nikesh Bhagat, could you please open a support ticket and send us sample project that reproduces the issue. This will allow us to find out what is going wrong on your side.

All the best,
Genady Sergeev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
bharti ten
Top achievements
Rank 1
answered on 23 Feb 2010, 10:36 PM
Hello telerik team,


The second option of

var descValue = $get('<%= RadUpload1.ClientID %>' + 'Title' + i).value; worked perfectly fine.

Thank you so much.
I also want to know how to set a  Required field validator for each of the additional text boxes that 
i have added to the radupload using  onClientAdded function.

Like i want to say "*Required"  for Description text boxes when they are left blank , rather than 

using "Custom validator" and giving one error message.

Please help.

Thank you,
Bharathi
0
Mona
Top achievements
Rank 1
answered on 24 Mar 2011, 10:49 AM
Hello,

I am using this code to implement a textbox to feed some title for every uploaded file but the problem I am facing is :

Assembly 'Telerik.Web.UI, Version=2008.3.1016.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4' does not contain a Web resource with name 'Telerik.Web.UI.Common.jQueryInclude.js'.


I also tried to download this jquery from given link but not found any such query.
please help.
0
adnan
Top achievements
Rank 1
answered on 03 May 2011, 12:43 PM
HI Guys,

i have a situation here,

I want to upload multiple files / Documents
i am using RadUpload
each file has specific name, which is already exist in database (Table Name : DocumentNames)

i want to show these documents in the radiobuttonlist, which should be attached with RadUpload
when user click on (Add) button of radupload, RadioButtonList should appear without the last selected document/item.

can anybody help me out
0
Peter Filipov
Telerik team
answered on 05 May 2011, 01:30 PM
Hello bharti ten,

When it is not possible to use required field validator, because the number of the validated inputs is unknown.

My suggestion about your required field validator for RadUpload without jQuery is: when an input is added on the client, OnClientAdded event is fired. Get with args.get_fileInputField().id method all IDs and save them into array. Before page submit check the input values. Here is my sample code:
<div>
    <telerik:RadScriptManager runat="server" ID="RadScriptManager"></telerik:RadScriptManager>
    <telerik:RadUpload runat="server" ID="RadUpload" MaxFileSize="500000000" OnClientAdded="onClientAdded" ></telerik:RadUpload>
        <input type="button" onclick="onButtonClick()"/>
    </div>
    </form>
    <script type="text/javascript">
        var inputs = new Array();
        function onClientAdded(sender, args){           
             inputs.push(args.get_fileInputField().id);
        }
 
        function onButtonClick(){
            debugger;
            for(var i=0; i<inputs.length;i++){
                var input = document.getElementById(inputs[i]);
                alert(input.value);
            }
            // if all input values are different than "" , then submit the page
             // document.form1.submit();
        }
 
         
    </script>

Regarding Mona's post, the issue is probably caused because you are using old version of our controls.

To avoid the thread to become inconsistent Mona, adnan please open new support tickets for your issues. 

Regards,
Peter Filipov
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Upload (Obsolete)
Asked by
Priya Priya
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Priya Priya
Top achievements
Rank 1
Genady Sergeev
Telerik team
Nikesh Bhagat
Top achievements
Rank 1
Sebastien Desemberg
Top achievements
Rank 1
bharti ten
Top achievements
Rank 1
Mona
Top achievements
Rank 1
adnan
Top achievements
Rank 1
Peter Filipov
Telerik team
Share this question
or