472,330 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,330 software developers and data experts.

Visibility on postback of dynamically-created HTML controls

I have a problem maybe one of you could help me with. I've created a data
entry screen with lots of dynamically-created client-side controls. I
create HTML texboxes client-side by assigning a value to the td.innerHTML
property. The UI is done, and I now want to post back the user's changes
and update my business object in .NET. But when I postback, I can't see any
of my dynamically created HTML controls in VB .NET. How do I make them
visible?

I understand that in order to make my HTML controls visible to .NET on
postback, I have to include the runat='server' property. But when I include
this in my dynamically-created control, it works fine as long as there are
no variables in the declaration of the control. For example,
The following works fine -- I can see the value on postback in .NET by
typing request.item("fff"):

var abc = '<INPUT type="text" id="fff" runat='server' value="abc" >';

objTD.innerHTML = abc

And this works too -- No compile error, but I can't see the value on
postback:

var myID = "fff"

var abc = '<INPUT type="text" id="' + myID + '" value="abc" >';

objTD.innerHTML = abc

But I get a parse error telling me that + myID + is not a valid identifier
if I do this.

var myID = "fff"

var abc = '<INPUT type="text" id="' + myID + '" runat='server'
value="abc" >';

objTD.innerHTML = abc

Apparently, if you specify a runat='server' parameter, the .NET compiler
fully evaluates the value assigned to innerHTML at compile-time, rather than
at runtime, but it evaluates it at runtime if the runat parameter is not
there. Unless I want all of my TD declarations to have the same ID, I need
a way to change the ID for each field.

Question 1: Is there a way for me to dynamically create HTML controls that
have unique IDs that are visible to the server?

Question 2: If not, is there a better way to get my data, which currently
lives as a two-dimensional array in Javascript, from the client to the
server?

Sorry for the long post. Thanks for any thoughts or input you might have.

Marcus


Nov 19 '05 #1
1 3291
Dynamically created controls have to be handled differently from declared
controls,. as they are 'lost' during the page_load event after postback. The
normal way to handle them is to recreate them in the page_init and then
repopulate them in the page_load (theres a good article on this @
http://aspnet.4guysfromrolla.com/articles/092904-1.aspx)

Alternatively,as the contents of a form have been posted you can read the
values back out of the request.form's collection.

"Marcus" <ma***********@hotmail.com> wrote in message
news:uV**************@TK2MSFTNGP14.phx.gbl...
I have a problem maybe one of you could help me with. I've created a data
entry screen with lots of dynamically-created client-side controls. I
create HTML texboxes client-side by assigning a value to the td.innerHTML
property. The UI is done, and I now want to post back the user's changes
and update my business object in .NET. But when I postback, I can't see any of my dynamically created HTML controls in VB .NET. How do I make them
visible?

I understand that in order to make my HTML controls visible to .NET on
postback, I have to include the runat='server' property. But when I include this in my dynamically-created control, it works fine as long as there are
no variables in the declaration of the control. For example,
The following works fine -- I can see the value on postback in .NET by
typing request.item("fff"):

var abc = '<INPUT type="text" id="fff" runat='server' value="abc" >';

objTD.innerHTML = abc

And this works too -- No compile error, but I can't see the value on
postback:

var myID = "fff"

var abc = '<INPUT type="text" id="' + myID + '" value="abc" >';

objTD.innerHTML = abc

But I get a parse error telling me that + myID + is not a valid identifier
if I do this.

var myID = "fff"

var abc = '<INPUT type="text" id="' + myID + '" runat='server'
value="abc" >';

objTD.innerHTML = abc

Apparently, if you specify a runat='server' parameter, the .NET compiler
fully evaluates the value assigned to innerHTML at compile-time, rather than at runtime, but it evaluates it at runtime if the runat parameter is not
there. Unless I want all of my TD declarations to have the same ID, I need a way to change the ID for each field.

Question 1: Is there a way for me to dynamically create HTML controls that have unique IDs that are visible to the server?

Question 2: If not, is there a better way to get my data, which currently
lives as a two-dimensional array in Javascript, from the client to the
server?

Sorry for the long post. Thanks for any thoughts or input you might have.

Marcus


Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: bitsyboffin | last post by:
Hi all, does anybody know of a bug in MacIE which prevents style.display = 'none' and style.visibility = 'hidden' from "sticking" in MacIE? I'm...
7
by: moondaddy | last post by:
I have a user control being used instead of a frame page. when the user clicks on a menu item I need to send the ID (integer value) of that menu as...
3
by: Guadala Harry | last post by:
I have a simple user control (see below) that has EnableViewState="true". I place it on an ASPX page at runtime using a PlaceHolder - which also has...
2
by: echan8 | last post by:
I have a dropdown list in a datagrid which I am dynamically adding items to with JavaScript. When I try to access the value of the dropdown list...
0
by: Michel Couche | last post by:
Hello, I would like to programmatically set the visibility of a selectedWizardStep after clicking on a button contained in an other one. I...
2
by: celoftis | last post by:
Using VS2005, ASP.NET. Check out the tree view on this page: http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.aspx ...
0
by: btysgtmajor | last post by:
Hi all, I'm hoping I've just done something stupid here, but... I have two panels on an ASP.NET web form. When the page first loads (i.e. not...
4
by: Mario Vargas | last post by:
Hello all, I am trying to dynamically add elements to a select list (which is running on the server, runat="server") with JavaScript, but when I...
1
by: dontspammenow | last post by:
If I put a asp button on a page with a runat=server attribute and then set it's visibility to FALSE, so that it doesn't display on the page, but...
0
by: rvdnieuwenhuizen | last post by:
Hi, The problem I cannot seem to solve: I have a page with a button control. In the On_Click eventhandler I dynamically add one TextBox each...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.