Solved

Boolean variables in ASP.net

Posted on 2004-04-07
4
1,898 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import a excel sheet in a grid 2 45
Data Analysis 7 59
Open telerik datetime picker programmatically 13 42
Help with adding xml file as datasource in MS Report 8 19
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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