查找从主页面继承的页面的加载事件的控件

时间:2022-10-16 15:52:42

I am unable to find controls on load events of a page that is inherited from Master page. When i am trying to do so, it`s giving exception, On tracing i found that controls are not found on page and showing "null". Here is my code

我无法找到从母版页继承的页面的加载事件的控件。当我试图这样做时,它会给出异常,在跟踪时我发现在页面上找不到控件并显示“null”。这是我的代码

for (int i = 0; i <= 6; i++)
{
  Image Img =FindControl("ourPimg0") as Image;
  Img.ImageUrl=("Handler.ashx?ImgID=" + dt1.Rows[i][0].ToString()+"&ImageType="+"projectimage");
  Label l1 = (Label)Page.FindControl("lbl_P" + i + "H1");
  l1.Text = dt1.Rows[i][1].ToString();
  Label l2 = (Label)Page.FindControl("lbl_P" + i + "H2");
  l2.Text = dt1.Rows[0][2].ToString();
  HyperLink hylnk = (HyperLink)Page.FindControl("ourPClink" + i);
  hylnk.NavigateUrl=("ProjectDetails.aspx?ID=" + dt1.Rows[i][0].ToString());
}

Any suggestion is appreciated. Ravi

任何建议表示赞赏。拉维

2 个解决方案

#1


1  

if you are trying to find control inside the master page you should this.Master.FindControl("controlName").

如果你想在母版页中找到控件你应该这个.Master.FindControl(“controlName”)。

Other case is with you are inside master page and want to find a control inside a page so you should ContentPlaceHolder1.FindControl("controlName").

其他情况是你在主页面内,并希望在页面内找到一个控件,所以你应该ContentPlaceHolder1.FindControl(“controlName”)。

Please also check:

还请检查:

#2


0  

while checking for controls in child page use the below code

检查子页面中的控件时使用以下代码

ContentPlaceHolder1.FindControl("controlName") .It lists out the control for that particular field.

ContentPlaceHolder1.FindControl(“controlName”)。它列出了该特定字段的控件。

#1


1  

if you are trying to find control inside the master page you should this.Master.FindControl("controlName").

如果你想在母版页中找到控件你应该这个.Master.FindControl(“controlName”)。

Other case is with you are inside master page and want to find a control inside a page so you should ContentPlaceHolder1.FindControl("controlName").

其他情况是你在主页面内,并希望在页面内找到一个控件,所以你应该ContentPlaceHolder1.FindControl(“controlName”)。

Please also check:

还请检查:

#2


0  

while checking for controls in child page use the below code

检查子页面中的控件时使用以下代码

ContentPlaceHolder1.FindControl("controlName") .It lists out the control for that particular field.

ContentPlaceHolder1.FindControl(“controlName”)。它列出了该特定字段的控件。