Solved

Boolean variables in ASP.net

Posted on 2004-04-07
4
1,897 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TimeZone, day light savings, Sql server, asp.net 6 38
Iteration Help (Asp.net VB) 5 35
Name Space error VS2015 1 35
Input parameteres to DragOver 2 34
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 a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…

735 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