By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

combining dynamic forms with file upload

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"IRAS Blues" <li*****@yahoo.com> wrote in message
news:d8**************************@posting.google.c om...
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

Nov 18 '05 #2

P: n/a
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" <re*************@monarchmed.com> wrote in message news:<O4**************@TK2MSFTNGP10.phx.gbl>...
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

"IRAS Blues" <li*****@yahoo.com> wrote in message
news:d8**************************@posting.google.c om...
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

Nov 18 '05 #3

P: n/a
"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" wrote:
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" <re*************@monarchmed.com> wrote in message news:<O4**************@TK2MSFTNGP10.phx.gbl>...
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

"IRAS Blues" <li*****@yahoo.com> wrote in message
news:d8**************************@posting.google.c om...
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

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.