Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Boolean variables in ASP.net

Posted on 2004-04-07
4
Medium Priority
?
1,908 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 750 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
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…
Screencast - Getting to Know the Pipeline

879 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