Solved

Reference value of dynamic control in VB ASP.NET

Posted on 2011-09-14
5
263 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
  • 2
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
disrupt earned 250 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 250 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now