Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

IIF is always evaluating true

Posted on 2009-05-05
4
Medium Priority
?
722 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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 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