473,785 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1422
"Jack Russell" <ja***@norubbis h.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=controlbyna meindex&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***@norubbis h.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=controlbyna meindex&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

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

Similar topics

1
4077
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" name="nameCheckbox">optional</p> <p><input id="idRadio1" name="nameRadio">yes<input id="idRadio2" name="nameRadio">no</p> <p><select id="idSelect" name="nameSelect"><option value="a">a</option><option value="b">b</option><option value="c">c</option></select></p>
3
2796
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 IDs. Thanks Vivek
3
3347
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 o=getobject(,"ConsoleApplication2.Program") msgbox o.TestString
5
1709
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() { //this.Controls.Clear(); CustomFieldUtil objCustomFieldUtil = new CustomFieldUtil(); DataTable objDT = objCustomFieldUtil.GetDataTable("custom"); for(intCount = 0; intCount < objDT.Rows.Count; intCount++)
2
1656
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 reference of the masterpage '_ctl0_cphMain_MyHiddenField' etc. The app uses dynamically assigned masterpages to the control name on the page changes depending on the masterpage being used. There is no
1
6986
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? LoginButton.Attributes.Add("onmouseover", "this.className = 'buttonsmallover'"); LoginButton.Attributes.Add("onmouseout", "this.className = 'buttonsmall'"); -- Jeff Lynch
0
1658
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"() RETURNS TABLE AS Begin RETURN
9
2651
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 to another location because it populates a Textbox in the user control page. Thanks Andrew
9
1916
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 the name in my string variable, then I know I have the correct control and can proceed to change the property. However all that searching seems like overkill. Does anyone know of a way to directly access the control if it's name is in a string...
1
21036
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 continue." Let me first say, my feedback page and thank you pages are in the same domain. my webservice.htc file is in the same diectory as my feedback.jsp page. I am using IE 6 (my companiy is IE specific) If i click OK, all code and everything...
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9954
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.