Find Control by ID
Syntax#
control.FindControl("Id Of The Control To Be Found")
Remarks#
FindControl
is not recursive, it only searches through immediate children of the control- There is an overload
FindControl(String, int)
which is not indented for public usage - If nothing is found,
FindControl
returnsnull
, so this is often a good idea to verify result for being notnull
Accessing the TextBox Control in aspx Page
TextBox txt = (TextBox)FindControl(yourtxt_Id);
Find a control in a GridView, Repeater, ListView etc.
If the Control has rows.
TextBox tb = GridView1.Rows[i].FindControl("TextBox1") as TextBox;
Or if it has items.
TextBox tb = Repeater1.Items[i].FindControl("TextBox1") as TextBox;