473,480 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Access text box using variable


Hi,

I am trying to access a text control using a variable name rather than a
fixed id.

ie I have a text controls called "tx1" "tx2" "tx3" etc. and i want to set
the control using
something like

"id" & variable

rather than "id1"

Is there a way in asp.net i can access a text control using the DOM so don't
have to have a hardcoded id in my code?

TIA.


Nov 30 '05 #1
5 1889
Sure, both on server and client side you can declare variables and assign to
them values:

TextBox tb;
tb = tx1;
tb.Text = "whatever";

Eliyahu

"flash" <no****@hotmail.com> wrote in message
news:3v*************@individual.net...

Hi,

I am trying to access a text control using a variable name rather than a
fixed id.

ie I have a text controls called "tx1" "tx2" "tx3" etc. and i want to set
the control using
something like

"id" & variable

rather than "id1"

Is there a way in asp.net i can access a text control using the DOM so
don't
have to have a hardcoded id in my code?

TIA.


Nov 30 '05 #2
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:e3**************@TK2MSFTNGP14.phx.gbl...
Is there a way in asp.net i can access a text control using the DOM so
don't have to have a hardcoded in my code?

TIA.

Sure, both on server and client side you can declare variables and assign to them values:

TextBox tb;
tb = tx1;
tb.Text = "whatever";

Eliyahu


Um, you've lost me a bit there Eliyahu.

if I have

<asp:textbox id="St1" runat=server/>

Then how would I access the textbox in serverside vb.net without using its
name of ST1 but using avaraible set to "ST1".

Cheers.

Nov 30 '05 #3
I think this might help:

private void Button1_Click(object sender, EventArgs MyEventArgs)
{
// Find control on page.
Control myControl1 = FindControl("TextBox2");
if(myControl1!=null)
{
// Get control's parent.
Control myControl2 = myControl1.Parent;
Response.Write("Parent of the text box is : " +
myControl2.ID);
}
else
{
Response.Write("Control not found");
}
}

More info:
http://msdn.microsoft.com/library/de...ntroltopic.asp

Cheers
Remy Blaettler
www.collaboral.com

Nov 30 '05 #4
Is not it what I wrote? tb is the variable, you set it to ST1, whatever vb
syntax is (something like 'dim tb' and 'tb=ST1' ? I don't write in vb), and
use tb.Text instead of ST1.Text.

Eliyahu

"flash" <no****@hotmail.com> wrote in message
news:3v*************@individual.net...
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:e3**************@TK2MSFTNGP14.phx.gbl...
> Is there a way in asp.net i can access a text control using the DOM so
> don't have to have a hardcoded in my code?
>
> TIA.
>


Sure, both on server and client side you can declare variables and assign

to
them values:

TextBox tb;
tb = tx1;
tb.Text = "whatever";

Eliyahu


Um, you've lost me a bit there Eliyahu.

if I have

<asp:textbox id="St1" runat=server/>

Then how would I access the textbox in serverside vb.net without using its
name of ST1 but using avaraible set to "ST1".

Cheers.

Nov 30 '05 #5

"Remy" <rb********@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I think this might help:

private void Button1_Click(object sender, EventArgs MyEventArgs)
{
// Find control on page.
Control myControl1 = FindControl("TextBox2");
if(myControl1!=null)
{
// Get control's parent.
Control myControl2 = myControl1.Parent;
Response.Write("Parent of the text box is : " +
myControl2.ID);
}
else
{
Response.Write("Control not found");
}
}

More info:
http://msdn.microsoft.com/library/de...ntroltopic.asp


Thanks, just what I needed. Final code is

dim x as string
x="st" & 0
dim y as textbox
y = FindControl(x)
y.text="hello"

Nov 30 '05 #6

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

Similar topics

7
6387
by: rickcheney | last post by:
I just changed my Access 2002 database to a SQL Server ADP project. I had a form where the user entered a value into a text box and when a command button on the form was clicked a Report was...
14
5382
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
4704
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...
2
3006
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2...
4
12410
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
4
2751
by: Debbiedo | last post by:
My software program outputs an XML Driving Directions file that I need to input into an Access table (although if need be I can import a dbf or xls) so that I can relate one of the fields...
5
15043
ADezii
by: ADezii | last post by:
Periodically, the same or similar question appears in our Access Forum: How can I use Excel Functions within Access? For this reason, I decided to make this Subject TheScripts Tip of the Week. In...
13
3697
by: magickarle | last post by:
Hi, I got a pass-through query (that takes about 15 mins to process) I would like to integrate variables to it. IE: something simple: Select EmplID from empl_Lst where empl_lst.timestamp between...
2
19389
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
7041
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
7081
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...
1
4776
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...
0
4481
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...
0
2995
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...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
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 ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
179
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...

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.