UserControl:FindControl无法找到内部控件 [英] UserControl: FindControl cannot find the inner control
本文介绍了UserControl:FindControl无法找到内部控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果用户控件带有文本框。我在aspx页面上实例化这个用户控件。
现在页面加载事件如下所示:
If have a user control with a textbox. I instantiate this usercontrol on an aspx page.
Now the page load event looks like this:
protected void Page_Load(object sender, EventArgs e)
{
TrialControl tc = new TrialControl(); //This is my Usercontrol
Label labelUctext = (Label)(tc.FindControl("labelText1"));
if (labelUctext != null)
{
if (labelUctext.Text != String.Empty)
{
labelText.Text = labelUctext.Text;
}
}
}
这里labelUctext始终保持NULL。因此它无法找到内部标签。非常基本的问题,但我做错了什么?
Here labelUctext always holds NULL. thus it is not able to find the inner label. Extremely basic question, but what am I doing wrong?
推荐答案
将此方法添加到您的usercontrol.cs并调用此方法
喜欢这个
string str = usercontrol.AddProperty;
add this method into your usercontrol.cs and call this method
like this
string str=usercontrol.AddProperty;
public string AddProperty
{
get
{
return labelText1.Text;
}
set
{
labelText1.Text = value;
}
}
foreach(grdroomavail.Rows中的GridViewRow gr)
{
(Literal)tt =((Literal)gr.FindControl(ltrroom)as Literal).Text
}
foreach (GridViewRow gr in grdroomavail.Rows)
{
(Literal)tt=((Literal)gr.FindControl("ltrroom") as Literal).Text
}
这篇关于UserControl:FindControl无法找到内部控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文