I have a public property returned from my code-behind class to aspx page:
window.MyWIndow.IsFull = '<%=this.IsFull%>';
In code-behind it is defined this way:
public bool IsFull
{
get;
set;
}
Now, when I use it in my javascript file, I have the following code:
var isShow = myself.IsFull;
This way isShow is either 'True' or 'False'
I need to convert it on the page level, so isShow is boolean instead of string.
So I can write the if else logic
How can I do it?
You can use JSON.parse('true');
JSON.parse(isShow.toLowerCase());
Try the example below.
var result = ['True', 'False']
var isShow = result[Math.round(Math.random())];
console.log(JSON.parse(isShow.toLowerCase()));
If you know it's always going to return the string True and False, you could just use;
window.MyWindow.IsFull = '<%=this.IsFull%>' === "True";
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