Link to home
Start Free TrialLog in
Avatar of cgcmq
cgcmqFlag for Canada

asked on

IIF is always evaluating true

I am trying to set the visibility of an asp.net tag to false, based on a condition, using IIF.  The statement is always evaluating to true.

Visible='<%# IIF (1=2,false,true) %>'

The above code, when placed in a tag, is still visible even though the condition is clearly false. The complete tag is:

<asp:HyperLink ID="HyperLink1" runat="server" Text="[more]" NavigateUrl="~/exhibits/chilling_out/en/more.aspx" Visible='<%# IIF (1=2,false,true) %>' />

What am I doing wrong?
Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America image

Not sure, but what about:
Visible='<%#  = IIF (1=2,false,true) %>'
or
Visible='<% = IIF (1=2,false,true) %>'
Avatar of Peter Hart

the expression use are using "1=2"  is not a boolean expression

this may explain more.....

http://msdn.microsoft.com/en-us/library/27ydhh0d(VS.71).aspx

and

http://www.secretgeek.net/iif_function.asp
Avatar of cgcmq

ASKER

Visible='<%#  = IIF (1=2,false,true) %>' will not compile due to the leading = sign.

I am not sure why 1 = 2 would not be considered a boolean expression.  

The links you refer to discuss the problems of using an IIF when there is a chance that either the true or false part of the statement cannot be executed such as is the case when dividing by 0.  In my case, both true and false are valid values of the visibility attribute.
ASKER CERTIFIED SOLUTION
Avatar of vkarumbaiah
vkarumbaiah
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial