Solved

IIF is always evaluating true

Posted on 2009-05-05
4
699 Views
Last Modified: 2013-11-07
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?
0
Comment
Question by:cgcmq
4 Comments
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 24310112
Not sure, but what about:
Visible='<%#  = IIF (1=2,false,true) %>'
or
Visible='<% = IIF (1=2,false,true) %>'
0
 
LVL 28

Expert Comment

by:chilternPC
ID: 24310116

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
0
 

Author Comment

by:cgcmq
ID: 24310155
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.
0
 
LVL 1

Accepted Solution

by:
vkarumbaiah earned 500 total points
ID: 24314505
I'm not sure if server tags can evaluate expressions so I doubt you could do this in a server tag.
You could put this in a code behind as follows

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        HyperLink1.Visible = IIf((1 = 2), True, False)
    End Sub

also note your logic in the iif is incorrect
it should be
 IIf((1 = 2), True, False)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now