Public Overridable Function FindControl ( _ id As String _ ) As Control
Dim instance As Control Dim id As String Dim returnValue As Control returnValue = instance.FindControl(id)
public virtual Control FindControl ( string id )
public: virtual Control^ FindControl ( String^ id )
public Control FindControl ( String id )
public function FindControl ( id : String ) : Control
要查找的控件的标识符。
下面的示例定义了一个 Button1_Click 事件处理程序。在被调用时,此处理程序使用 FindControl 方法来在包含页上查找 ID 属性为 TextBox2 的控件。如果找到了该控件,则使用 Parent 属性确定其父控件,并将父控件的 ID 写入页中。如果没有找到 TextBox2,则将“Control Not Found”写入页中。
Private Sub Button1_Click(sender As Object, MyEventArgs As EventArgs) ' Find control on page. Dim myControl1 As Control = FindControl("TextBox2") If (Not myControl1 Is Nothing) ' Get control's parent. Dim myControl2 As Control = myControl1.Parent Response.Write("Parent of the text box is : " & myControl2.ID) Else Response.Write("Control not found.....") End If End Sub
private void Button1_Click(object sender, EventArgs MyEventArgs) { // Find control on page. Control myControl1 = FindControl("TextBox2"); if(myControl1!=null) { // Get control's parent. Control myControl2 = myControl1.Parent; Response.Write("Parent of the text box is : " + myControl2.ID); } else { Response.Write("Control not found"); } }
private void Button1_Click(Object sender, EventArgs myEventArgs) { // Find control on page. Control myControl1 = FindControl("TextBox2"); if (myControl1 != null) { // Get control's parent. Control myControl2 = myControl1.get_Parent(); this.get_Response().Write("Parent of the text box is : " + myControl2.get_ID()); } else { this.get_Response().Write("Control not found"); } }//Button1_Click
Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。