combining dynamic forms with file upload

I

IRAS Blues

Hi all,

I've got a form that consists of a bunch of textboxes and also file
upload inputs. For both sets of fields, I need to be able to add in
additional elements on the fly. This is done by an "Add Textbox" and
"Add Upload Fields" button that I use Javascript to add to the fields.
I use client-side Javascript only to add to the fields.

The problem comes when I submit the form. When I submit the form, the
files uploaded present no problems when I use Request.Files. But no
matter what, I can't seem to access the additional textboxes created
by Javascript from my server code. I have tried using FindControl and
Request.Form but both do not work.

One workaround I can think of is to use server-side code to add the
elements by doing a Postback everytime I click on the "Add Textbox"
button, but that would invariably involved uploading the files
selected in the File Upload fields which I want to prevent.

Does anybody know of a better way to do this?

Thanks
Wong
 
E

Eliyahu Goldin

Wong,

Have you included the additional textboxes in children property of any of
form controls? They need to belong to form's object hierarchy.
Alternatively, you can prepare all textboxes in advance and just hide/show
them as needed.

Eliyahu
 
I

IRAS Blues

These elements are inside Web User Control object which is called from
the default form in the web application I'm building. So the hierarchy
is sort of like this:

<form id="defaultForm"> -> <wuc id="defaultUploadForm"> -> <table
id="upLoadTable"> -> <table id="Part_Table"> -> <input
id="Part_Num_*">

Note that the * in Part_Num_* denotes whatever number is generated
when I click on the Add Part button.

using "this.FindControl" in the code behind page for
defaultUploadForm, I seem to be able to call upLoadTable & Part_Table
but I CANNOT seem to access anything inside it, including just any of
its rows e.g. this.upLoadTable.Rows[0].Cells[0].InnerHtml.ToString().
All of them give an object reference error.

What can I be doing wrong here?

Thank you very much...
 
G

Guest

"I have tried using FindControl and Request.Form but both do not work."

FindControl:
remember that server-side code is only aware of page content (eg. elements)
that are either created during the initial request or subsequent postback.
So your server-side code will not be aware of any client-side added elements
(eg. <input> tags). Hence, "this.FindControl" will fail to see your new
textboxes.

Request.Form:
Your example indicated an "ID" attribute on the new <input> tag, but did not
include a "name" attribute. If memory serves, the "name" attribute must be
included for an <input> value to be submitted with a form. Further, the
following is quoted from the MSDN library regarding the "name" attribute:

==> The NAME attribute cannot be set at run time on elements dynamically
==> created with the createElement method. To create an element with a
==> name attribute, include the attribute and value when using the
createElement method.

hence the following Javascript should work:

var newTextbox = document.createElement('<input type="text"
name="part_num_11">') ;
[appropriate cell from part_table].appendChild(newTextbox) ;

Hope this helps.

IRAS Blues said:
These elements are inside Web User Control object which is called from
the default form in the web application I'm building. So the hierarchy
is sort of like this:

<form id="defaultForm"> -> <wuc id="defaultUploadForm"> -> <table
id="upLoadTable"> -> <table id="Part_Table"> -> <input
id="Part_Num_*">

Note that the * in Part_Num_* denotes whatever number is generated
when I click on the Add Part button.

using "this.FindControl" in the code behind page for
defaultUploadForm, I seem to be able to call upLoadTable & Part_Table
but I CANNOT seem to access anything inside it, including just any of
its rows e.g. this.upLoadTable.Rows[0].Cells[0].InnerHtml.ToString().
All of them give an object reference error.

What can I be doing wrong here?

Thank you very much...


Eliyahu Goldin said:
Wong,

Have you included the additional textboxes in children property of any of
form controls? They need to belong to form's object hierarchy.
Alternatively, you can prepare all textboxes in advance and just hide/show
them as needed.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top