Control.FindControl 方法 在当前的命名容器中搜索带指定 id 参数的服务器控件。参数 id 要查找的控件的标识符。 返回值 指定的控件,或为空引用(Visual Basic 中为 Nothing)(如果指定的控件不存在的话)。 [C#] 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"); } }
上面的方法不行啊, if (toolBar1 != null) { } 判断不出来父控件也是在要在重新创建之后才加上的,Control.FindControl 方法没有用。UP
{
}
{
//....
}
在当前的命名容器中搜索带指定 id 参数的服务器控件。参数
id
要查找的控件的标识符。
返回值
指定的控件,或为空引用(Visual Basic 中为 Nothing)(如果指定的控件不存在的话)。
[C#]
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");
}
}
if (toolBar1 != null)
{
}
判断不出来父控件也是在要在重新创建之后才加上的,Control.FindControl 方法没有用。UP
别无它法了么?