Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Re: Help with retreiving values from dynamically added controls


Message #1 by "snehalata" <snehalata@i...> on Tue, 25 Jun 2002 07:29:03
hi,

I came across a situation where I need to add radio buttons dynamically 
and retrieve values from those controls.

1. First of all we need a ID to identify the control from server side, 
otherwise asp.net puts some id while rendering the page ,which we cannot 
capture.
  
	So give some 'ID' for each control that gets added dynamically.
	
	Ex:
		dim rdbtn as RadioButtonList
		rdbtn.id="rdCheck"


2. In order to capture the values from those control we need to declare 
them
as we used to do for other controls, but which we can not do as they were 
added dynamically

As asp.net renders them to some html controls, we can access them using

Request.form("id of the control")

Ex:
	Request.form("rdCheck")



Hope the above works to you too.

Regards,
Sneha

> Sorry if this has been covered before but it is frustrating me. 
> 
> I am going to take a moment to set the scene. 
> 
> I have a page that has a textbox and a button on it. 
> You enter a value in the textbox then click the button. 
> 
> The page reloads with the textbox and the button. 
> Also now the page has generated a number of placeholders and entered 
tables into each one. Also another set of textboxes appear. 
> The number of placeholders, and therefore tables, and extra text is 
determined by the number you entered into the textbox. 
> 
> The extra text boxes are for you to enter the number of cells you 
require in each of the sections. 
> 
> This is as far as I can get. I simply cannot find a way to get at the 
values which are typed into the generated textboxes and therefore cannot 
determine how many cells are required in the sections. 
> 
> What is it that I am over looking? 
> 
> I have tried accessing the controls through using the findcontrol and 
the ID which I have sepcified. Also I have tried to access them by using a 
foreach and going through the controls collection. 
> 
> I have managed to get the actual controls. However not the values which 
they hold. Using the stated methods I found my way to the actual control 
objects. Once there I cast them to (textbox) and then tried to access the 
textbox.value 
> This returned nothing. 
> I thought about the fact that because they were created dynamically they 
may have to be added to the page again after post back to be able to 
access them. This helped in no way at all. I also enabled viewstate and 
again nothing. 
> 
> Someone out there must know where I am going wrong. 
> 
> Aiden 

  Return to Index