无法在page_load中使用master.findcontrol [英] not working master.findcontrol in page_load
本文介绍了无法在page_load中使用master.findcontrol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void Page_Load(object sender, EventArgs e)
{
TextBox tb = (TextBox)Master.FindControl("txtEmployee_code");
}
在主页上设置属性.将此属性称为另一个页面,但不起作用
公共TextBox tb
{
得到{返回txtEmployee_code; }
设置{txtEmployee_code =值; }
}
set the properties in master page. call this properties another page, but not working
public TextBox tb
{
get { return txtEmployee_code; }
set { txtEmployee_code = value; }
}
推荐答案
1.检查是否在page指令中添加了mastertype
声明.
2.如果要使用set/gettextbox
值,则不要执行findcontrol,而是在masterpage
中定义一个公共属性以进行设置并获取它,然后从页面中调用此属性.
1. Check whether you have added themastertype
declaration in the page directive.
2. if you want to use set/get thetextbox
value then instead of doing a findcontrol define a public property in themasterpage
for setting and getting it and then call this property from the page.
我的第一个猜测是您的控件实际上不在母版页上,而是在嵌套页上.如果是这样,将找不到它.您将需要执行以下操作:
My first guess would be that your control is not actually on the master page but on a nested page. If so, this won''t find it. You would need to do something like:
this.Form.FindControl("txtEmployee_code");
您可以在此处找到更多示例和更多想法(请务必查看评论,因为它们还有其他人尝试过的选项):
http://csharporcas.blogspot.com/2006/05/master-page-find- control.html [^ ]
You can find more examples and more ideas here (make sure to look at the comments, since they have other options people have tried):
http://csharporcas.blogspot.com/2006/05/master-page-find-control.html[^]
尝试TextBox tb =(TextBox)Page.FindControl("txtEmployee_code");
try TextBox tb = (TextBox)Page.FindControl("txtEmployee_code");
这篇关于无法在page_load中使用master.findcontrol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文