设置后属性具有相同的值
问:
我在 .aspx
文件中有一个面板,其visibility = false,在我的代码中的某个时刻,我设置了visibility = true。但是问题是:当我跟踪代码我发现可见属性仍然等于 false ,尽管我将其设置为 true 。 我的面板名称是:pnl_DetailsGeneral
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedValue == "2")
{
drp_Week.Enabled = false;
gv_Details.Visible = false;
panel_rmv.Visible = false;
pnl_DetailsGeneral.Visible = true;//Here when i put a break point and after setting visible to true i find `pnl_DetailsGeneral.Visible = false`
gv_DetailsGeneral.Visible = true;
BindGridGeneral();
}
else if (RadioButtonList1.SelectedValue == "1")
{
drp_Week.Enabled = true;
gv_Details.Visible = true;
gv_DetailsGeneral.Visible = false;
pnl_DetailsGeneral.Visible = false;
if (drp_Week.SelectedValue != "-1")
{
BindGrid();
}
}
}
什么可能导致此问题?
Q:
I have a panel the visibility = false in the .aspx
file ,at some point in my code i set the visibility = true.but the problem is: when i trace the code i find the visible property still equal false ,although i set it to true .
My panel name is :pnl_DetailsGeneral
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedValue == "2")
{
drp_Week.Enabled = false;
gv_Details.Visible = false;
panel_rmv.Visible = false;
pnl_DetailsGeneral.Visible = true;//Here when i put a break point and after setting visible to true i find `pnl_DetailsGeneral.Visible = false`
gv_DetailsGeneral.Visible = true;
BindGridGeneral();
}
else if (RadioButtonList1.SelectedValue == "1")
{
drp_Week.Enabled = true;
gv_Details.Visible = true;
gv_DetailsGeneral.Visible = false;
pnl_DetailsGeneral.Visible = false;
if (drp_Week.SelectedValue != "-1")
{
BindGrid();
}
}
}
what may cause this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Visible 属性有一个特殊的属性:当您读取该值时,它不仅报告控件本身,还报告其父控件。您获得的价值是“真实”的可见性。
所以显然你的控件的父控件仍然是不可见的!
当您将父级设置为可见时,您的控件也将变得可见。
The Visible property has a special property: when you read the value it not only reports on the control itself but also on it's parent. The value you get is the "real" visibility.
So apparently the parent of your control is still invisible!
When you set the parent to Visible, your control will become visible also.
我相信如果任何父级具有 Visible = false,则
Control.Visible
属性将返回 false。I believe the
Control.Visible
property returns false if any parent has Visible = false.一个可能的解释是通过控制层次结构的隐式可见性。
例如,如果您有一个包含其他控件的占位符,并且该占位符已将 Visible 设置为 false,则它的所有子控件也将 Visible 设置为 false,即使您自己显式设置该属性也是如此。
A possible explanation is implicit visibility through the control hierarchy.
For instance, if you have a placeholder than contains other controls, and the placeholder has visible set to false, all of it's child controls will also have Visible set the false, even if you set the property explicitly yourself.