473,320 Members | 1,865 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,320 software developers and data experts.

Access object with a name

Hi,
How can I access object with a name like this:

string ObjectName = "TextBox1";
TextBox(ObjectName).Text = "bla bla bla"

Thanks.
Nov 16 '05 #1
4 1465
Hi Sergey,
How can I access object with a name like this:

string ObjectName = "TextBox1";
TextBox(ObjectName).Text = "bla bla bla"


As far as I understand this "pseudocode" you mean:

Find an Textbox on my form and set the Property "Text" to "bla bla bla".
Is this correct!?
<code>
foreach(Control c in this.Controls)
{
if (string.Compare(c.Name, "textBox1") == 0)
{
if (c is TextBox)
{
TextBox tb = (TextBox) c;
tb.Text = "bla bla bla";
}
}
</code>

--
Greetings
Jochen
Nov 16 '05 #2
If you are using WebControls, you can use the FindControl(controlName)
method

"Sergey Atun" <s@s.com> schrieb im Newsbeitrag
news:uW**************@TK2MSFTNGP09.phx.gbl...
Hi,
How can I access object with a name like this:

string ObjectName = "TextBox1";
TextBox(ObjectName).Text = "bla bla bla"

Thanks.

Nov 16 '05 #3
Sergey,

You have two choices here in general. The first is to place each
reference to a control in a Hashtable (or a Dictionary if you are using .NET
2.0) and then key it on whatever you wish (the name, a number, etc, etc).

The other option is to use reflection on the class containing the
control, and then expose that (however, the class doesn't always have to
have a class level reference to the control for it to be visible).

Of course, in environments like ASP.NET, you might be provided with a
mechanism such as this already.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Sergey Atun" <s@s.com> wrote in message
news:uW**************@TK2MSFTNGP09.phx.gbl...
Hi,
How can I access object with a name like this:

string ObjectName = "TextBox1";
TextBox(ObjectName).Text = "bla bla bla"

Thanks.

Nov 16 '05 #4
I saw that you laready got the answer of your question. Bare in mind,
though, that control don't haveto have names. Especialy in the case of
dynamicaly created controls porbably no one bothers of setting names

--

Stoitcho Goutsev (100) [C# MVP]
"Sergey Atun" <s@s.com> wrote in message
news:uW**************@TK2MSFTNGP09.phx.gbl...
Hi,
How can I access object with a name like this:

string ObjectName = "TextBox1";
TextBox(ObjectName).Text = "bla bla bla"

Thanks.

Nov 16 '05 #5

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

Similar topics

14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
4
by: Otis Hunter | last post by:
I have been given an Access Database which contains a table that has an OLE object field that contains a Word document. That table contains hundreds of records. I would like to find out how I can...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
by: Harry Devine | last post by:
I have a DataGrid that is configured to use the Edit/Update/Cancel concept correctly. My grid shows values from 5 database fields. I only need to update that last 4 fields. The last field is a...
2
by: Dean Slindee | last post by:
Anybody written code in VB.NET to: 1) show a print preview window of reports already written and stored in an Access 2002 database; or 2) execute the print of a report stored in an Access 2002...
4
by: alexandre.brisebois | last post by:
Hi, I am using access 2003, I would like to know if there is an option to reorganize the tables in a maner that is readable, as we can do in sql sever 2000 or 2005. I have been given a database...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
6
by: Adam Donahue | last post by:
As an exercise I'm attempting to write a metaclass that causes an exception to be thrown whenever a user tries to access 'attributes' (in the traditional sense) via a direct reference. Consider:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.