开发者

How to find control within ContentPlaceholder and placeholder?

开发者 https://www.devze.com 2023-01-17 03:38 出处:网络
I am adding controls dynamically to Plac开发者_C百科eHolder which within ContentPlaceHolder var t = (ContentPlaceHolder)Master.FindControl(\"ContentPlaceHolder1\");

I am adding controls dynamically to Plac开发者_C百科eHolder which within ContentPlaceHolder

var t = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
var t1 = (PlaceHolder)mpContentPlaceHolder.FindControl("PlaceHolderName");

var t2 = (DropDownList)t1.FindControl("ControlID");

It looks like I am missing something because t2 is always null


If you want to find controls of master page then you can find like :

Label l = Master.FindControl("label1") as Label;

And in your case for finding control from contentplaceholder you can find control like :

  TextBox TB=
  Master.FindControl("ContentPlaceHolder1").FindControl("textbox1") as
  TextBox;


I found gridview with this method:

GridView gv =(GridView)Master.FindControl("ContentPlaceHolder1").FindControl("gvRD"); 


If you are adding controls dynamically and you are trying to find the control after postback you will not find them.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号