Click here to Skip to main content
15,891,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
<script type = "text/javascript">
       var counter = 0;
       function AddFileUpload() {
           counter++;
           var div = document.createElement('DIV');

           div.innerHTML = '<input id="file' +
     counter + '" name = "file' +
     counter + '" type="file" />  Name Of Certificate : <input  id="TextBox' +
     counter + '" name="TextBox' +
     counter + '" type="text" />   Year Obtained : <input  id="TextBox2' +
     counter + '" name="TextBox2' +
     counter + '" type="text" />   <input id="Button' +
     counter + '" type="button" value="Remove"  önclick = "RemoveFileUpload(this)" />';

           document.getElementById("FileUploadContainer").appendChild(div);
       }
       function RemoveFileUpload(div) {
           document.getElementById("FileUploadContainer").removeChild(div.parentNode);
       }
</script>

my C# code
C#
protected void PersonalButtonNext3_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        BSEnterpriseLib dal = new BSEnterpriseLib();
        string msg = "";
       

    for (int i = 0; i < Request.Files.Count; i++)
    {
        HttpPostedFile PostedFile = Request.Files[i];
        if (PostedFile.ContentLength > 0)
        {
            string FileName = System.IO.Path.GetFileName(PostedFile.FileName);
            
//here I need to get the ID of the text boxes and get the data inputed into them and then use //this data to input into the database, while iterating     

            //insert into the database here
            PostedFile.SaveAs(Server.MapPath("Uploaded Documents\\") + FileName);
        }
    }

    messagelabel.text = "Successful";
    }
Posted
v3
Comments
Ajay_Babu 15-Feb-14 7:25am    
you giving textbox id statically using javascript?
ebukaegonu2 18-Feb-14 3:04am    
yes i am. and i need to get the id from my code behind, but ive solved the problem, thanks

protected void PersonalButtonNext3_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
BSEnterpriseLib dal = new BSEnterpriseLib();
string msg = "";


for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFile PostedFile = Request.Files[i];
if (PostedFile.ContentLength > 0)
{
string FileName = System.IO.Path.GetFileName(PostedFile.FileName);
FileName = Session["StaffIDforTabs"].ToString() + "_" + FileName;

var SChoolAttended = Request.Form["TextBox2" + i];
var NameOfCertificate = Request.Form["TextBox" + i];
var YearObtained = Request.Form["TextBox3" + i];


//insert into the database here
dal.InsertApplicationAcademicQualification(FileName, "~/Uploaded Documents/" + FileName, Convert.ToInt32(Session["StaffIDforTabs"]), SChoolAttended, YearObtained, NameOfCertificate, ref msg);


if (msg != "")
{
MessageBox.Show("Unable to Upload Certificates as a result of " + msg);
return;
}










PostedFile.SaveAs(Server.MapPath("Uploaded Documents\\") + FileName);
}
}


ShowError("Successful");
MessageBox.Show("Successful");
WebTab1.SelectedIndex = 2;

}
 
Share this answer
 
You can't get the values of these Dynamic Controls as they are getting created at Client Side using JavaScript.
Instead create them from Code Behind.

Or you can define them in aspx page with its visibility false (by setting style="display:none;"). In that JavaScript function, just make them visible.
 
Share this answer
 
v2
Comments
badr slaoui 2-Jul-14 6:00am    
if a control is defined with visibilty false , it is not rendered at all to the client side then you cannot call it at all.
By visibility false, I meant to set the display property to none actually. I did not mean to set the Visible="false".

Anyway, I am updating my answer. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900