我们在建立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") 差不多。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2021-10-14
  • 2021-09-10
  • 2021-07-27
  • 2022-12-23
猜你喜欢
  • 2021-12-08
  • 2022-02-22
  • 2021-09-06
  • 2022-12-23
  • 2021-11-08
  • 2021-06-29
相关资源
相似解决方案