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 1 3387
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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 making some graphical checkboxes & radios (I know,...
|
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
a parameter in the postback of the user control...
|
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
EnableViewState="true".
After a postback, the...
|
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 on postback, there
is no value. The value is...
|
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 found the following in an article from D. Esposito...
|
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
When you hover over the border between the two...
|
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 a postback), I set the visibility of both panels...
|
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 postback, the new
elements are lost. I'm not sure...
|
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 have a click event for the button in the code...
|
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 time the button is clicked. I add the
textboxes to...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |