How to Get the Index of a Control on a Web Form?
Posted on 2010-11-23
After searching the KB, I did not find the answer to this question, but I'll bet the answer is out there some where. I've done this in VB, but cannot determine how to do this in C#.
On a web form, I have many textbox controls. One of the controls is named txtFirstName. In VB, if I were to assign the *name* of this control to a string variable, I could then reference the variable in order to access a control, instead of referencing the control directly. For example:
strControlName = "txtFirstName"
I would like to know how this is done in C#, either by referencing a variable that stores the control name, or by referencing the index value of a control. The following does not work in C#:
If I knew the index, maybe I could do something like:
intIndex = <control index value>