asp.net FindControl作用

我们在建立ASP.NET 页面的时候有事出现多容器控件,在这种情况ASP.NET 有时候服务识别控件那么我们就必须使用 FindControl 来查找:

然我们看看如何使用FindControl:

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");

   }

}

其实学过Javscript的朋友应该了解到  Asp.net 的 FindControl 的作用与 Javscript 中的 document.getElementById("id") 差不多。

posted @ 2011-08-24 16:55  蓝雨.Berners  阅读(4669)  评论(0编辑  收藏  举报