Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to pass in a boolean C# variable to a javascript variable and set it to true

Tags:

javascript

c#

Having issues where in my .aspx page I pass in a boolean variable (C#) to a javascript function that is expecting a boolean type.

BUt the C# variable returns True, and javascript doesn't like the uppercase.

myjavascript( <%= MyBooleanVariableInCSharp %> ); 

If I convert the c# variable to string, then my javascript variable becomes a string and not a js bool value!

what is the solution to this nightmare? lol

like image 398
mrblah Avatar asked Mar 18 '09 01:03

mrblah


People also ask

How do you declare a boolean in C?

Syntax to Declare Boolean Data Types in C: To declare a boolean data type in C we have to use a keyword named bool followed by a variable name. bool var_name; Here, bool is the keyword denoting the data-type and var_name is the variable name. A bool takes in real 1 bit, as we need only 2 different values(0 or 1).

Can you pass a bool by reference?

By using '&' you can pass it by reference.

What does C mean in boolean?

In C, Boolean is a data type that contains two types of values, i.e., 0 and 1. Basically, the bool type value represents two types of behavior, either true or false. Here, '0' represents false value, while '1' represents true value. In C Boolean, '0' is stored as 0, and another integer is stored as 1.

What should be included in a boolean in C?

In C, boolean is known as bool data type. To use boolean, a header file stdbool. h must be included to use bool in C. bool is an alias to _Bool to avoid breaking existing C code which might be using bool as an identifier.


1 Answers

Try this:

myjavascript( <%= MyBooleanVariableInCSharp.ToString().ToLower() %> ); 
like image 188
Andrew Hare Avatar answered Sep 26 '22 03:09

Andrew Hare