473,418 Members | 4,816 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,418 software developers and data experts.

Accessing a control by name

If I know the name of a control can I access it (change its text etc)
without looking through all the controls for one with this name?

Thanks

Jack Russell
Nov 23 '05 #1
10 1398
"Jack Russell" <ja***@norubbish.tpg.com.au> schrieb:
If I know the name of a control can I access it (change its text etc)
without looking through all the controls for one with this name?


Accessing controls by their names or indices
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 23 '05 #2
Jack:

Absolutely!

myTextBox.Text = "I changed the text value"

will do just that!

Am I missing something?

"Jack Russell" wrote:
If I know the name of a control can I access it (change its text etc)
without looking through all the controls for one with this name?

Thanks

Jack Russell

Nov 23 '05 #3
Sorry should have been more explicit, I have the name as a string.
So dim s as string
s="label1"
Now I want to say s.text="Hello"

vvenk wrote:
Jack:

Absolutely!

myTextBox.Text = "I changed the text value"

will do just that!

Am I missing something?

"Jack Russell" wrote:

If I know the name of a control can I access it (change its text etc)
without looking through all the controls for one with this name?

Thanks

Jack Russell

S
Nov 23 '05 #4
Sorry Herfried, I should have been more explicit. I was hoping I could
get to it directly without searching the array. Guess that is what I
will have to do.

Jack
Herfried K. Wagner [MVP] wrote:
"Jack Russell" <ja***@norubbish.tpg.com.au> schrieb:
If I know the name of a control can I access it (change its text etc)
without looking through all the controls for one with this name?

Accessing controls by their names or indices
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en>

Nov 23 '05 #5
Jack Russell wrote:
If I know the name of a control can I access it (change its text etc)
without looking through all the controls for one with this name?

Thanks

Jack Russell


you could make a hashtable of the controls you want access to and look
it up that way.

Chris
Nov 23 '05 #6
Jack,
So dim s as string
s="label1"
Now I want to say s.text="Hello"

This is a typical scrypting language feature which is not as simple as this
in VB.Net.

In fact there is no need for it, you know all the labels which are in your
classes either by indice or eiter by there internal name.

It does not help

Cor
Nov 23 '05 #7
Cor Ligthert [MVP] wrote:
Jack,

So dim s as string
s="label1"
Now I want to say s.text="Hello"


This is a typical scrypting language feature which is not as simple as this
in VB.Net.

In fact there is no need for it, you know all the labels which are in your
classes either by indice or eiter by there internal name.

It does not help

Cor

Cor,

For rather obscure reasons I am trying to write a simple text file of
all the controls and their text so that a dumb user can edit it and I
read it back. Anyway, I have got it working the long way.
Thanks for your help
Jack
Nov 23 '05 #8
Jack,
For rather obscure reasons I am trying to write a simple text file of all
the controls and their text so that a dumb user can edit it and I read it
back. Anyway, I have got it working the long way.
Thanks for your help

Than you know the "name" from that label and can you find it using one of
those methods Herfried has showed. An alternative is using the tag, which
makes your less dependend when you have changes. However that is only an
extention from the methods Herfried probably shows (I don't have to look to
it, to know what those are).

Don't think looping is slow in VBNet. It is that fast that every other
method takes often so many overhead, that looping outclasses it almost
forever.

I hope this helps,

Cor
Nov 23 '05 #9
Cor Ligthert [MVP] wrote:
Jack,

For rather obscure reasons I am trying to write a simple text file of all
the controls and their text so that a dumb user can edit it and I read it
back. Anyway, I have got it working the long way.
Thanks for your help


Than you know the "name" from that label and can you find it using one of
those methods Herfried has showed. An alternative is using the tag, which
makes your less dependend when you have changes. However that is only an
extention from the methods Herfried probably shows (I don't have to look to
it, to know what those are).

Don't think looping is slow in VBNet. It is that fast that every other
method takes often so many overhead, that looping outclasses it almost
forever.

I hope this helps,

Cor

Cor,

Thanks, your advice is always welcome. I will probably have some more
questions as it goes along.

Jack
Nov 23 '05 #10
"Jack Russell" <ja***@norubbish.tpg.com.au> schrieb:
Sorry Herfried, I should have been more explicit. I was hoping I could
get to it directly without searching the array. Guess that is what I
will have to do.


An alternative way is using a hashtable, as shown in the article.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 23 '05 #11

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

Similar topics

1
by: DU | last post by:
Assuming you have a typical form built in this manner: <form action="..."> <p><input id="idInputText" name="nameInputText" type="text" size="20"></p> <p><input id="idCheckbox"...
3
by: Vivek Sharma | last post by:
Hi, I have created a dropdownlist as a web user control. I am using its multiple instances on the webpage. How do I access the selectedValue of each instance? All the instances have different...
3
by: AdamM | last post by:
Hi all, When I run my VbScript, I get the error: "ActiveX component can't create object: 'getobject'. Error 800A01AD". Any ideas what I did wrong? Here's my VBScript: dim o set...
5
by: Jonathan Williams | last post by:
Hi, I have an object which inherits from WebControl (CUSTOM : WebControl) In this object I have code in which I add child contols: protected override void CreateChildControls() {...
2
by: Stu | last post by:
Hi, I am migrating a large app to .Net 2 and am having problems with accessing hidden fields using javascript. As I am using masterpages the control names are prefixed with the control...
1
by: Jeff Lynch | last post by:
I'd like to add the following attributes to the Login control's Login Button to create a CSS rollover effect. How can I access the control's login button from the page's code-behind? ...
0
by: aakash | last post by:
Hello Guys I am upsizing ms access project to give it a ms sql connectivity I am having problem in accessing form control values in ms sql function CREATE FUNCTION "ReportList DateRange"() ...
9
by: J055 | last post by:
Hi I have a standard asp page which uses a MasterPage. The MasterPage contains a User control. How can I access a public method in the User control from my WebForm page? I can't move the method...
9
by: JohnR | last post by:
I have the name of a control in a string variable and I want to change one of the controls properties. Right now I recursively scan all the controls on the form until I get one whose name matches...
1
by: beebee | last post by:
Hi all i am getting the following error message when my feedback form is posted: "This page is accessing information that is not under its control. This poses a security risk. Doyou want to...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.