master页面后面的代码访问控制 [英] Access control of master on code behind of masterpage
问题描述
我正在尝试在母版页的代码隐藏文件上访问masterpage的contextplace holder的控件。
我是通过创建属性来实现的,但它给了我一个stackoverflow的错误。
控件是按钮
I am trying to access a control of contextplace holder of masterpage on the code behind file of masterpage.
I did it by creating property but it gives me a error of stackoverflow.
controls are buttons
public Button seeProfole
{
get { return seeProfole; }
set { seeProfole = value; }
}
使用:
its use :
seeProfole.Visible = true;
plz help
我尝试了什么:
我正在尝试访问masterpage的contextplace holder的控件母版页后面的代码。
我是通过创建属性来实现的,但是它给了我一个stackoverflow错误。
控件是按钮
公共按钮seeProfole
{
get {return seeProfole; }
set {seeProfole = value; }
}
plz help
plz help
What I have tried:
I am trying to access a control of contextplace holder of masterpage on the code behind file of masterpage.
I did it by creating property but it gives me a error of stackoverflow.
controls are buttons
public Button seeProfole
{
get { return seeProfole; }
set { seeProfole = value; }
}
plz help
推荐答案
你是否感到惊讶StackOverflowException
?您的属性访问者调用属性访问器,该访问器调用属性访问器,该访问器调用....
您的属性访问者需要返回控件,而不是属性。如果属性名称与控件ID相同,则您需要更改一个。请记住,C#区分大小写,因此您只需更改大小写:
Are you surprised by theStackOverflowException
? Your property accessor calls the property accessor, which calls the property accessor, which calls the ....
Your property accessor needs to return the control, not the property. If the property name is the same as the control ID, then you'll need to change one. Remember, C# is case-sensitive, so you could simply change the case:
public Button SeeProfole
{
get { return seeProfole; }
set { seeProfole = value; }
}
按钮seepro =(按钮)Master.FindControl(seeProfole);
为我工作
Button seepro = (Button)Master.FindControl("seeProfole");
work for me
这篇关于master页面后面的代码访问控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!