?
Solved

Reference value of dynamic control in VB ASP.NET

Posted on 2011-09-14
5
Medium Priority
?
271 Views
Last Modified: 2012-05-12
I have an ASP.NET web page that dynamically creates a table with 3 columns and a variable number of rows.

Col 1 contains a checkbox - chkx
Col 2 contains a textbox - txtx
Col 3 contains a label - lblx

where x is a number based on how many times we've ran round the loop.

All the above are created dynamically during the page init event and are givin an ID at run-time. (code snipit below)

Everything works fine, however, when I click one of the checkboxes I need to get the value in the coresponding textbox & label

i.e. when I click chk1, then I need the value in txt1 & lbl1, but as the controls are dynamic, the code behind doesn't recognise the ID of the control, so... txt1.Text fails validation..

So how do I reference the control's value
Dim nCheckBox As CheckBox = New CheckBox()
nCheckBox.Checked = False
nCheckBox.EnableViewState = True
nCheckBox.ID = "chk" & counter
nCheckBox.AutoPostBack = True

AddHandler nCheckBox.CheckedChanged, AddressOf CheckBox1_CheckedChanged

Open in new window

0
Comment
Question by:BrianFord
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
disrupt earned 1000 total points
ID: 36540100
Take a look at this:

http://techbrij.com/197/retrieve-value-of-dynamic-controls-in-asp-net

shows you how to retrieve dynamic controls
0
 

Author Comment

by:BrianFord
ID: 36540158
thanks,

but I find that hard to follow as it's C# and I'm not familiar with that, I'm using VB

It looks like I have to iterate through all the dynamic control to see if it's a checkbox, then if it's a checkbox and it's checked I still don't see how to get the value from the textbox that's in the adjacent cell of the same row?
0
 
LVL 16

Expert Comment

by:disrupt
ID: 36540247
you can use this to conver to vb .net:

http://www.developerfusion.com/tools/convert/csharp-to-vb/
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 1000 total points
ID: 36570554
Try using the FindControl method of the container. The container would be the page if the controls are directly added to page or a form or a panel or a grid etc. So you can use

CType(Page.FindControl("txt1"), TextBox).Text
0
 

Author Closing Comment

by:BrianFord
ID: 36570640
thank you very much
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question