C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Javascript »

Creating File upload Controls using Java Script


Posted Date: 30 Oct 2009    Resource Type: Code Snippets    Category: Javascript
Author: PraveenMember Level: Diamond    
Rating: 1 out of 5Points: 5



Hi,

A Small Article which Creates Multiple File Upload Control(s) and you can get that file upload controls using a button click Event

Design Code

<--asp:LinkButton ID="lnkCreate" runat="server" Text="Add More File"><--/asp:LinkButton>
<--div id="FileUpload">
<--/div>
<--asp:Button ID="btn" runat="server" Text="Get Files" />
<--input type="hidden" runat="server" id="HiddenFileUploads" />


Server Side Code for Link Button and Button onclick to Call Java Script


protected void Page_Load(object sender, EventArgs e)
{
if (!(IsPostBack))
{
lnkCreate.Attributes.Add("onclick", "return CreateFile();");
btn.Attributes.Add("onclick", "return CheckFiles('" + HiddenFileUploads.ClientID + "');");
}
}


javascript function for link button click Event and button click Event


<--script type="text/javascript">
var i=0*1;
function CreateFile()
{
var newDiv=document.createElement("div");
var FileUp=document.createElement("input");
FileUp.type="file";
FileUp.setAttribute("id","File"+i);
newDiv.setAttribute("id","Div"+i);
newDiv.appendChild(FileUp);
document.getElementById("FileUpload").appendChild(newDiv);
i=i+1;
return false;
}
function CheckFiles(HiddenId)
{
var input=document.getElementById("FileUpload").getElementsByTagName("input");
var UploadedFiles="123,";
for(var i=0;i {
if(input[i].type=='file')
{
UploadedFiles=UploadedFiles+document.getElementById(input[i].id).value+",";
}
}
UploadedFiles=UploadedFiles.substring(4);
alert(UploadedFiles);
document.getElementById(HiddenId).value=UploadedFiles;
return false;
}

<--/script>



so in button click event as am saving the selected file(s) in hidden control with ',' delimiter so you can get that on server side using hidden control value


hope this will help some one!

Attachments

  • MultipleFileUploadControls (34502-30841-MultipleFileUpload.zip)


  • Responses


    No responses found. Be the first to respond and make money from revenue sharing program.

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    Creating File upload Controls using Java Script at run time  .  Creating File upload Controls at run time  .  Creating dynamic File upload Controls using Java Script at runtime  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: Reading XML Data from JavaScript
    Previous Resource: Disable Browser Back Button Functionality using JavaScript
    Return to Discussion Resource Index
    Post New Resource
    Category: Javascript


    Post resources and earn money!
     
    More Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use