.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

add dynamically fileupload control

Posted By:      Posted Date: October 04, 2010    Points: 0   Category :ASP.Net

Hi Everyone,

               I have a requirement where i need to add fileupload controls dinamically when Add button is clicked.  In my form i have one Add button and one Save button.

Each time ADD button is clicked one fileupload control must be added to form and i succeded in getting this.

Here is the code

   static int i;
    FileUpload fuPic;
    protected void Page_Load(object sender, EventArgs e)
        if (Session["pnl"] != null)
            Panel pnlfinal = (Panel)Session["pnl"];


protected void btnAdd_Click(object sender, EventArgs e)
        if (i <= 4)
            i = i + 1;

View Complete Post

More Related Resource Links

Server side validation of Fileupload control not working



I've tried this method in my code behind to try and validate that the Fileupload control has a file or not. I get the error message the the event "Server Validate" cannot be found. Can anyone tell why? Thanks.

Public Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate

' Get file name

        Dim uploadAvatar As FileUpload = DirectCast(AdvertisementForm.FindControl("uploadAvatar"), FileUpload)

        Dim UploadFileName As String = uploadAvatar.PostedFile.FileName

        If UploadFileName = "" Then
            ' There is no file selected
            args.IsValid = False
            Dim Extension As String = UploadFileName.Substring(UploadFileName.L

using the linqDataSource control programmatically (dynamically)



my scenario is this: I want to use the linqDataSource control to bind data to a gridview for it's efficient built-in paging and sorting features *but* I don't want the data to be bound until the user has input various search parameters, so I need to bind the data from a button click event. Also, the search options will be somewhat complex in that there will be several optional search parameters, via various dropdowns and textboxes, so I can't just declaratively/statically setup all the WHERE parameters on the linqDataSource (at least I'm assuming I can't, or that it may result in poor performance if I do and just assign default values like the everything wildcard '%' for the cases the user doesn't use a particular search parameter). Given that brief description, here is an example of what I'm doing, but with only one WHERE parameter for simplicity, the real code will be adding anywhere from 1 to about 12 WHERE parameters depending on how the user sets the search options in the GUI.

the linqDataSource on the aspx page:

<asp:LinqDataSource ID="ldsMain" runat="server" 
        Select="new (field1, field2, field3, etc..)" 

Persist data in a dynamically populated ListBox in a user control


Hi All,

I am trying to persist data in a dynamically populated ListBox in a user control. Here are the details

I have a user control which contains a a listBox and button. On Page_Load of user control I am populating the ListBox control with some values. On Click of button, I am trying to fetch the values which I have selected in ListBox. Though this seems very simple and straight forward I am unable to fetch values.

My Page_Load Function

void Page_Load(object sender, EventArgs e)










My Click Function

Protected Void Button1_Click(object sender, EventArgs e)


       string strValue = listBox.SelectedValue



I have placed brake point at Page_Load and on click function, I am seeing that the moment the breakpoin

Dynamically load user control without postback


Hi all,

I need urgent help. (c#coding)

In my base page, I have a dropdownlist control which loads different usercontrols on selectedindexchanged event.

While loading these usercontrols, my page postbacks all the page. I used updatepanel but again same problem.

Is there any way to load controls without postback? I Really need help as soon as possible.

Here is my code:

protected void Page_Init(object sender, EventArgs e)
        if (Session["control"] != null)
            string c = Session["control"].ToString();
            if (c == "1")
                iuc = (IlkogretimUC)LoadControl("~/Controls/Ilkogretim.ascx");
                dl.SelectedValue = Session["control"].ToString();
            else if (c == "2")
                luc = (LiseUC)LoadControl("~/Controls/LiseUC.ascx");
                dl.SelectedValue = Session["control"].ToString();
            else if (c == "3")
                youc = (YuksekokulUC)LoadControl("~/Controls/Yuksekokul.ascx");

FileUpload Control with membership and roles


Hi Everyone!

I'm pretty new to development using Microsoft technologies.

I'm trying to build a portal kind of an application in asp.net, in which one of the functionality is letting people log in and upload their documents. The upload page is only accessible to registered users of the portal.


I would like to track the user uploaded files according to their userIds.

Is it possible to use the FileUpload Control and C# to fetch the current user id, create a directory with the same name(as that of userID) in the file system and upload the files( multiple file upload, if necessary) into it?

Also another admin page would have to be able to see the list of files uploaded by the specific user and download it if necessary.

Could anyone help me with this?

I'm also expecting alternate solutions to the problem.

Awaiting a response.

Thanks in advance 


Want to Create Table Dynamically With text Control in WinForm Csharp

Hello To All... from Many Days i m tryng to create a simple table using csharp in WinForm.Which will include textbox in each cell according the Passed No of Col & Row. but not getting the proper result. Actually i want to trace each cell data and want to save each cell data to data base : eg. in cell 11(1col & 1row) i m having Combobox which having some item list and when the user select the list item the data will save to the database. Regards, Praveen    What is the Key of Life ... Its Sharing Your Thought & Knowledge ...

Getting an error using FileUpload Control on a server.

Hello FriendsI m getting a problem while executing the following code for my website.This code works perfactly on localhost but when I use d same code on my webpage on the server it does nothing...even it doesnt return any error msg.Plz help me...protected void BtnUpload_Click(object sender, EventArgs e) {        int intFileSizeLimit = 1000;               string strFileNameWithPath = FileUpload1.PostedFile.FileName;               string strExtensionName = System.IO.Path.GetExtension(strFileNameWithPath);              string strFileName = System.IO.Path.GetFileName(strFileNameWithPath);           int intFileSize = FileUpload1.PostedFile.ContentLength / 1024;                              strExtensionName = strExtensionName.ToLower();        if (strExtensionName.Equals(".doc") || strExtensionName.Equals(".txt") || strExtensionName.Equals(".docx"))        {      

few questions about fileupload control

hey im currently using this to save pictures to a certin folderImgUpload.SaveAs(Server.MapPath("../Img/") + ImgUpload.FileName); my questions is 1. how do i avoid rewriting an image, in other words how do i check if there is another file using the same name? 2. how do i iterate on each image in the folder so that i can print certin html code for each img like for each image print this -> (<img src="Image_Path/Image-name.jpg/gif" width="?" height="?">   tnx

Dynamically (on client side) populating data control (repeater) when dropdown item is selected

Hello!I'm currently working on a project and I want to make as much things as possible performing on client side - with as little loading as possible.The project consist of three "main" pages. On one page I use jQuery DataTable plugin which is working great. One page has tabs (using jQuery). I want to put datacontrol (repeater) on this site and when  user selects one item in dropdown, data in repeater loads on client side, without performing the action on server.I wonder if this is possible and if somebody can give me some case to help with?Thanks!I hope I was clear enough. all the best

dynamically add control or register and set visibility

I have a classic asp website that I would like to convert to asp.net. The application is structured such that there is one central page that uses "server.execute" to call a page template and the template uses "server.execute" to call the page functionality. I am thinking that I will create a single asp.net page that sits alongside the current page. I can then slowly convert existing page functionality to usercontrols and add a little logic to redirect to the apropriate page based on the requested page functionality. Should I dynamically add the usercontrol to the page for the page functionality or should I register each control on the page and dynamically change the visibility? We don't add new functionality or update the exisiting functionality very often. Most changes are to the content stored in the database used by the pages.

Dynamically Binding Header of Repeater Control

Hi , I am stuck up into following Issue while binding Repeater control dynamically from database I have repeater control which I want to populate from database.. asp:Repeater id="Repeater1" runat="server">   <HeaderTemplate>      <table border="1">         <tr bgcolor="#ffcc99">            <th><asp:label id="Lname" runat ="server" text = "???"  ></asp:label></th> <th><asp:label id="Fname" runat ="server" text = "???"  ></asp:label></th>         </tr>   </HeaderTemplate>   <ItemTemplate>      <tr bgcolor="#ffcccc">        <td><%# DataBinder.Eval(Container.DataItem, "Col1") %></td>        <td><%# DataBinder.Eval(Container.DataItem, "Col2") %></td>      </tr>   </ItemTemplate>   <FooterTemplate>   </table>   </FooterTemplate></asp:Repeater&g

FileUpload control loses value on postback.

I'm having a little problem with my file uploading. Does anybody know how to maintain the value in the FileUpload control between server posts?I have a form which, among other things, uploads a file. I am using an FileUpload control (created dynamically) to let a user browse their PC for a file and then using the SaveAs method to upload the file to the server.When I'm selecting a file and Click on Next button for processing then selected file is lost.Same is happening with me with HtmlTextArea (dynamically generated) , the problem was that I was not again re-initializing the controls after postback. What I did is re-initialized it in Init method of placeholder (as I have created/placed all dynamic controls in placeholder ).But this thing is not working for fileupload control. I found solution in one of the forum is that "use hiddenField Control to transfer the selected file from the client to server"but this mechanism will only help to retain the name of file in a hidden variable and the FileUpload1.PostedFile.SaveAs(filename) will not work bcz of absense of object (fileupload1).here is code:protected void lnkbtnNext_Click(object sender, EventArgs e) { if (Session["pnl"].ToString() == "0") { /* other stuff code */ } else if (Session["pnl"].ToString() == "1")

How to Set default file name of image in FileUpload Control

helloi want to set  default value in Fileupload control.Because when i select file name using fileupload then save that file to sqlserver database i got problem when no file is select. so i found alternate of that i should store default image into database through fileupload control but now my query is how to set default image to fileupload control.please i want source code.i really need it......tnx in advance

dynamically created button control click event not firing first time?

HI im creating a button control in page int and im assing a click event for the button control. here the click event is not firing for the first time.can anyone help me with this? here is my code. Button btn = new Button(); btn.ID = "btn"; btn.Click += new EventHandler(btn_Click); Panel1.Controls.Add(btn); Panel1.Controls.Add(new LiteralControl(""));

Dynamically add user control with events


I'm trying to make web form with two placeholders. Firs holder contains user control witch has list of buttons, each button opens different user control to second placeholder.

I get it to show user control in second placeholder but i can't get dynamically created user controls to fire events.

So how i can dynamically create working user control with button click?

Here is how i create those controls:

 Dim toiminot As Control = LoadControl("~/kontrollit/" & field.Value)

"field" is hidden field containing filename of user control to be created.

All help is appreciated!

Dynamically Generate No of Control(like Label) depend upon database no of item


I have a requirment like 

i required a dynamically generated Control (like Label) depend upon Database no of item


  If i fetch Database text (like Name) fieldd 3 time than i am intrested to generate  label 3 time

for (int i=0;i<table.row.count;i++)


label label[i]=table.row[i][0].Tostring();


How can do the above because label[i] is not allowed

Khurram Shahzad

not retaining value of fileupload control in asp wizard control


I am developing a web application in asp.net and c#. I'm using an asp wizard control. there is  6 wizard steps in my wizard. In each phase im using many controls, so that many postback is done during execution.
I am using a asp fileupload control in second wizard step. My problem is that the value selected using fileupload control is not getting when i click wizard finsh button in the final step. values acquired using all other controls are available there.
Hope someone help me.
I just want to get the selected filename in last step. 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend