473,413 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Accessing HTMLControls created dynamically using Javascript during PostBack

Hi,

I have a page form where form elements are created dynamically using
Javascript instead of programatically at the code-behind level. I have
problems accessing the dynamically-created elements and would like to seek a
solution for this.

I had looked through several articles for accessing programatically-created
dynamic elements such as:
1)
http://msdn.microsoft.com/library/de.../viewstate.asp
2) http://aspnet.4guysfromrolla.com/articles/092904-1.aspx
3) http://www.codeproject.com/aspnet/retainingstate.asp

I had previously created a page according to those examples and I managed to
detect those elements using the following logic:
1) On first load, I would set a NoOfControls variable which tracks the
number of controls I created programatically.
2) During each PostBack, at the Page_Load stage I would re-create the
controls according to the NoOfControls variable.

The problem I face when I create elements purely at the client-side is that
I can't set the variable tracker similarly at the code-behind. So instead, I
put the tracker as a hidden input and attempt to accessing it during
PostBack. The logic works like this:

1) User would click an "Add Text Field" button and Javascript would create
the text field at the client side. The hidden input NoOfControls would also
increase.
2) When the form is submitted, I would try to access NoOfControls.Value at
Page_Load stage and then allocate the relevant IDs to the created elements.

However, I found that I can't access NoOfControls or any other form inputs
at Page_Load stage as this would give a "Object reference not set to an
instance of an object" error. This denies me the ability to get the values
of the programatically created elements.

Can anybody help me here? To further clarify, I am not trying to re-create
the form in the last view state to show the user. Instead, I am purely
trying to access the form inputs submitted so that I can process them. The
form itself can be shown in its default state.

Thanks!
Wong
Nov 18 '05 #1
1 3101
What you are trying to do isn't possible. When you post back, you post the
form to the page, so only the information in the form goes to the server.
If you create elements on the client side, they will show up visibly, but
that information will never make it to the server.

Best regards,
Jeffrey Palermo

"CS Wong" <pu*********@SPAMnascencetech.PLScom> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi,

I have a page form where form elements are created dynamically using
Javascript instead of programatically at the code-behind level. I have
problems accessing the dynamically-created elements and would like to seek a solution for this.

I had looked through several articles for accessing programatically-created dynamic elements such as:
1)
http://msdn.microsoft.com/library/de.../viewstate.asp 2) http://aspnet.4guysfromrolla.com/articles/092904-1.aspx
3) http://www.codeproject.com/aspnet/retainingstate.asp

I had previously created a page according to those examples and I managed to detect those elements using the following logic:
1) On first load, I would set a NoOfControls variable which tracks the
number of controls I created programatically.
2) During each PostBack, at the Page_Load stage I would re-create the
controls according to the NoOfControls variable.

The problem I face when I create elements purely at the client-side is that I can't set the variable tracker similarly at the code-behind. So instead, I put the tracker as a hidden input and attempt to accessing it during
PostBack. The logic works like this:

1) User would click an "Add Text Field" button and Javascript would create
the text field at the client side. The hidden input NoOfControls would also increase.
2) When the form is submitted, I would try to access NoOfControls.Value at
Page_Load stage and then allocate the relevant IDs to the created elements.
However, I found that I can't access NoOfControls or any other form inputs
at Page_Load stage as this would give a "Object reference not set to an
instance of an object" error. This denies me the ability to get the values
of the programatically created elements.

Can anybody help me here? To further clarify, I am not trying to re-create
the form in the last view state to show the user. Instead, I am purely
trying to access the form inputs submitted so that I can process them. The
form itself can be shown in its default state.

Thanks!
Wong

Nov 18 '05 #2

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

Similar topics

2
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have...
1
by: Mike | last post by:
I have a placeholder object in which I am dynamically placing controls based on a database query. Of course during postback these controls go away. I have seen other questions posed where someone...
0
by: AJP | last post by:
I have a child window which does the following after a button is pressed: Response.Write("<script>window.opener.__doPostBack('','');</script>"); but I get the following uncaught exception upon...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
1
by: Marcus | last post by:
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...
2
by: Pete Moss | last post by:
During a postback event, I am having trouble retrieving the state of a CheckBox Control that I am dynamically adding to a DataGrid Control using ASP.NET 1.1. I have no trouble adding the...
4
by: sydney.luu | last post by:
Hello All, I am programmatically building a table on my web page with one row and two columns. The first column contains a web server checkbox dynamically created and the second column simply...
3
by: jeroen.bolle | last post by:
I'm designing a form where the user can decide how many options for a poll he wants to add. There's a "+" button to dynamically add textboxes with javascript, without a postback. How do I access...
1
by: karthik25 | last post by:
Hi, The following code creates a tab container, 5 tab panels, buttons, labels. I was able to add event handlers to the button. But how am i supposed to access the dynamically created labels? For...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
agi2029
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.