finding a textbox with a search string

R

rodchar

hey all,
is there a way to find a textbox id with a search string in the code-behind?
thanks,
rodchar
 
N

Nathan Sokalski

What exactly do you mean by "find a textbox id"? Is there a Textbox that you
know something about that you do not know the id of? If you could please
clarify your question, I may be able to help you better.
 
R

rodchar

my controls are dynamically generated and i won't know what the id is until
runtime and i'd like to know what the first textbox id is so i can set focus
to it.
 
N

Nathan Sokalski

I don't believe a control has an ID you can use in the codebehind if you
don't assign a value to the ID property (I believe one is generated during
runtime, but this may not always be the same, so it is best to not try and
use it). Here are two possibilities you can try:

1. When generating the TextBoxes, set the ID property.

2. Enumerate through the Controls collection. As you look at each control,
check to see if it is a TextBox. I have not seen your entire code, and
sometimes using this technique is inefficient depending on what and how many
controls you have, so this may not always be the best choice.

I would suggest using #1, because it is simple and usually efficient. As far
as what value you should use as the ID, you can generate a String (probably
using the String.Format() method). Hopefully this helps.
 
R

rodchar

thanks for the help,
rod.

Nathan Sokalski said:
I don't believe a control has an ID you can use in the codebehind if you
don't assign a value to the ID property (I believe one is generated during
runtime, but this may not always be the same, so it is best to not try and
use it). Here are two possibilities you can try:

1. When generating the TextBoxes, set the ID property.

2. Enumerate through the Controls collection. As you look at each control,
check to see if it is a TextBox. I have not seen your entire code, and
sometimes using this technique is inefficient depending on what and how many
controls you have, so this may not always be the best choice.

I would suggest using #1, because it is simple and usually efficient. As far
as what value you should use as the ID, you can generate a String (probably
using the String.Format() method). Hopefully this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top