Bool变量未更新

1 c# asp.net visual-studio-2015

我有一个ImageButton类型的对象.我还有以下代码:

 LogManager.GetCurrentClassLogger().Log(LogLevel.Info, "###payWithVisa.Enabled ={0}; payWithVisa.Visible ={1}; canPayWithCard={2}", payWithVisa.Enabled, payWithVisa.Visible, canPayWithCard);

 payWithVisa.Enabled = canPayWithCard;
 payWithVisa.Visible = canPayWithCard;

 LogManager.GetCurrentClassLogger().Log(LogLevel.Info, "payWithVisa.Enabled ={0}; payWithVisa.Visible ={1}; canPayWithCard={2}", payWithVisa.Enabled, payWithVisa.Visible, canPayWithCard);
Run Code Online (Sandbox Code Playgroud)

这是相应的日志条目:

2016-03-29 11:37:49.1308|INFO|###payWithVisa.Enabled =True; payWithVisa.Visible =False; canPayWithCard=True
2016-03-29 11:37:49.1348|INFO|payWithVisa.Enabled =True; payWithVisa.Visible =False; canPayWithCard=True
Run Code Online (Sandbox Code Playgroud)

您可以看到变量payWithVisa.Visible未更新.尽管为其赋值为true的变量,它仍然是错误的.

有人可以帮我澄清一下是什么问题吗?

PS.使用的.NET框架:4.0

shr*_*t18 5

一种可能性(来自MSDN上的文档):

如果未呈现容器控件,即使将单个控件的Visible属性设置为true,也不会呈现其包含的任何控件.在这种情况下,即使您已将其明确设置为true,单个控件也会为Visible属性返回false.(也就是说,如果父控件的Visible属性设置为false,则子控件将继承该设置,并且该设置优先于任何本地设置.)

因此,您可能想要检查是否已首先呈现父控件.