I am calling a JS function from vb.net code behind, using RegisterClientScriptBlock
Initially this variable is a string having value as (true/false), then I parse it using custom code to booelan and I am passing this Boolean value as one of the parameter to a JavaScript function. Inside this JS function I am checking if that bool value is true or not using the below code. Now even though the bool value is false, the if(boolVariable) line of code is executing.
If I do an explicit check if(boolVariable == true) then it behaves as expected.
My understanding is that if(boolvariable) block should execute only if the boolVariable value is true. I am missing something ? Please guide.
Vb.net code
Dim jsCall As String = String.Format("jsfunction('{0}','{1}');", variable1, CustomParsers.Boolean(boolVariable)) // custom parser value will be true or false
Page.ClientScript.RegisterClientScriptBlock([GetType](), "script", jsCall, True)
JS code
function jsfunction(variable1,boolVariable) {
if (boolVariable) { // though boolVariable value is false this block is executing
// do something
}
}