Solved

IIF is always evaluating true

Posted on 2009-05-05
4
697 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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

6 Experts available now in Live!

Get 1:1 Help Now