Link to home
Start Free TrialLog in
Avatar of snowburnd
snowburnd

asked on

asp.net create HtmlInputFile controls dynamically

I am trying to create HtmlInputFile controls on the fly.  

Basically, the user will click a button to upload a file, a postback will happen and an input form should appear.
I want to make it so that they can click this for as many attachments as they want to send (I'll put limits in as needed, but for the purposes of getting this initial step working...)
the first HtmlInputFile control adds fine, which brings me to problem one:  I attach a file and it won't post afterwards (I have the form configured to multipart).  
the second problem is that the control disappears on postback and I can't have 2 of them.

If this is not doable I'll accept a solution that will let me upload attachments one a time and then relate them to the form that I'm uploading them from.  (this is a form for 2 tables, an "attachment" table that stores the files which is related to another table that stores the "tickets".

thanks in advance!

Let me know if you need any more info.  I've attached the snippet of code that creates and adds the control to the place holder.
private void AddAttachment_Click(object sender, EventArgs e)
{
	HtmlInputFile HIF;
	
	int i=0;
	IEnumerator IE = ((PlaceHolder)AddTicket.FindControl("AttachmentControls")).Controls.GetEnumerator();
	
	while (IE.MoveNext())
		{
			HIF = (HtmlInputFile)IE.Current;
			
			((PlaceHolder)AddTicket.FindControl("AttachmentControls")).Controls.Add(HIF);
			
			i++;
		}
	
	HIF = new HtmlInputFile();
	
	((PlaceHolder)AddTicket.FindControl("AttachmentControls")).Controls.Add(HIF);
	
	HIF.ID="Attachment"+i.ToString();
	
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of snowburnd
snowburnd

ASKER

Thanks for your response.

So I would have to create something like the OWA file upload or figure out a way to add them client side only without postback.  

This should give me enough to go on and stop me from beating my head on the wall any more.
Yes, you can add the upload controls either on the server side or the client side.