I have a boolean property in code-behind ASP.NET, now I want to use it in Javascript of mark-up file, but Javascript do not understand True, or False. SO now, I'm using this:
if ( '<%=IsTabVisible%>' == 'True'){
///
}
It works, but quite ugly. Is there a better way to do this?
Thank you
The way I see it you have three options:
A. Do what you are already doing.
B. Perform the if
test on the server-side, something like this:
<% if (IsTabVisible) { %> // client-side code here, whatever you had inside the brackets // of your original if statement <% } %>
C. Make sure you generate 'true' and 'false' in lowercase so that it will work as client-side JavaScript, something like this:
if (<%= IsTabVisible ? "true" : "false" %>)
Which will appear to the client as:
if (true)
or
if (false)
Option A may look a bit funny but it works fine. Option C produces pretty client-side code that probably nobody will see. My preference is Option B.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With