finding a textbox with a search string

  • Thread starter Thread starter rodchar
  • Start date Start date
R

rodchar

hey all,
is there a way to find a textbox id with a search string in the code-behind?
thanks,
rodchar
 
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.
 
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.
 
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.
 
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.
 
Back
Top