Google Search

Google
 

Sunday, December 2, 2007

Find ASP.NET Child Controls

To find out child control from parent control we use "$" acts as the delimiter.

Syntax for find out child control from parent control is parentControlID$childControlID.

Here, I give example to DefaultFocus attribute of the < form > element to set the focus to a TextBox nested within a FormView control.

< form id="form1" runat="server" DefaultFocus="vwTest$txtName" >
< div >
< asp:FormView ID="vwTest" runat="server" >
< ItemTemplate >
Name:
< asp:TextBox ID="txtName" runat="server"
Text='<%# Eval("FirstName") + " " + Eval("LastName") %>' / >
< /ItemTemplate >
< /asp:FormView >
< /div >
< /form >

Notice that the DefaultFocus attribute refers to the parent control first (the FormView) and then to the child control (the TextBox) using the vwTest$txtName syntax.