简体   繁体   English

布尔变量未更新

[英]Bool variables not being updated

I have a object of type ImageButton . 我有一个类型为ImageButton的对象。 Also I have following code: 我也有以下代码:

 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);

This is the corresponding log entry: 这是相应的日志条目:

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

You can see that the variable payWithVisa.Visible does not get updated. 您可以看到变量payWithVisa.Visible没有得到更新。 It is still false despite assigning to it a variable with value true. 尽管为其分配了值为true的变量,它仍然为false。

Can someone please help me clarify what is wrong? 有人可以帮我弄清楚什么是错的吗?

PS. PS。 .NET framework used: 4.0 使用的.NET Framework:4.0

One possibility (from the documentation on MSDN): 一种可能性(来自MSDN上的文档 ):

If a container control is not rendered, any controls that it contains will not be rendered even if you set the Visible property of an individual control to true. 如果未呈现容器控件,则即使将单个控件的Visible属性设置为true,也不会呈现其中包含的任何控件。 In that case, the individual control returns false for the Visible property even if you have explicitly set it to true. 在这种情况下,即使您已将Visible属性显式设置为true,单个控件也将返回false。 (That is, if the Visible property of the parent control is set to false, the child control inherits that setting and the setting takes precedence over any local setting.) (也就是说,如果父控件的Visible属性设置为false,则子控件将继承该设置,并且该设置优先于任何本地设置。)

Therefore, you may want to check if parent control has been rendered first. 因此,您可能要检查是否先呈现了父控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM