在当前的命名容器中搜索带指定
id 参数的服务器控件。
命名空间:System.Web.UI
程序集:System.Web(在 system.web.dll 中)
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
参数
- id
要查找的控件的标识符。
返回值
指定的控件,或为 空引用(在 Visual Basic 中为 Nothing)(如果指定的控件不存在的话)。
下面的示例定义了一个 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 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
.NET Framework
受以下版本支持:2.0、1.1、1.0