?
Solved

IIF is always evaluating true

Posted on 2009-05-05
4
Medium Priority
?
713 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 29

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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

765 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