Link to home
Start Free TrialLog in
Avatar of Luis_Romero
Luis_Romero

asked on

Boolean variables in ASP.net

I have a boolean variable in an aspx.vb page. I am putting a hidden varible in the form with the value of the boolean variable. The value is translated into True or False. When I try to read the value from the form and store it in the boolean variable I get the error 'Input string was not in a correct format'. I can create an if statement replacing the value from True/False to 1/0 but is there another way I can get this done? Thank you.
ASKER CERTIFIED SOLUTION
Avatar of dfiala13
dfiala13

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Luis_Romero
Luis_Romero

ASKER

Thanks for your information.

I also found a reference to the conversion function CBool(string)

That'll do it too.  Boolean.parse is .NET native and will work with VB.NET, C# (or any other language that you can develop in .NET in).  CBool is for VB.NET only.  
If you do not plan to access or change this variable in client-side script, why not put the boolean variable in the View State.  It will store on the page and be returned to you on the post back, i.e.:

    ' Store on Page Load
    Dim b As Boolean = True
    Me.ViewState("VAR_BOOL") = b

    ' Retrieve on Post Back
    Dim b As Boolean = Me.ViewState("VAR_BOOL")

A more ASP.NET way of doing things.

Good Luck,
WRK