Solved

Reference value of dynamic control in VB ASP.NET

Posted on 2011-09-14
5
268 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Groupbox Control ? 2 29
VB.Net - BackgroundWorker running multiple 5 47
Need help with a query 14 39
aspx ascx, c# 7 19
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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