Solved

Boolean variables in ASP.net

Posted on 2004-04-07
4
1,887 Views
Last Modified: 2013-11-25
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.
0
Comment
Question by:Luis_Romero
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
dfiala13 earned 250 total points
ID: 10777390


Sure,

Dim b as boolean

b = Boolean.Parse("True")

or

b = Boolean.Parse(somestring)
0
 

Author Comment

by:Luis_Romero
ID: 10778044
Thanks for your information.

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

0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10778361
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.  
0
 

Expert Comment

by:kingwr12
ID: 10780635
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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now