Session Variables (Get values)


I am storing some variables in Session, Double values, Integers and Strings.
Sometimes these values can be null or empty ("").

While retrieving these values from session I will declare a variable of its type. Let say for example I want to get a Double value from Session.

Dim dblAmount as Double
dblAmount = Session("sessAmount")

Here I am getting trouble when value is empty, its giving an error
Conversion from string "" to type 'Double' is not valid.

How to handle this kind of situations? Let me know your suggestion.



4/16/2007 2:00:02 PM 93655 articles. 6 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 25

Hi. Before assigning the value, check if the session variable is null, something like this:

If session("xxx") IsNot Nothing then

dblAmount = Session("sessAmount")

end if

4/16/2007 2:57:38 PM


This can be done like this in VB.NET


Dim dblAmount as Double
If Not IsNothing(Session("sessAmount")) Then
dblAmount = Session("sessAmount")
dblAmount = 0
End If




ASP.NET Hosting (HostingFest)
4/16/2007 3:09:04 PM

Another option: use Double.TryParse method.

My last project - .NET Tip of The
4/16/2007 3:15:48 PM

Similar Artilces:

How to get session variable value into a static variable
Hi, On page preinit i am adding few session variables. Now i want to retrive these session variable values into my static variables. protected void Page_PreInit(object sender, EventArgs e) {Session.Add("T", "Default"); Session.Add("T1", "Red"); Session.Add("T2", "Blue");   }   i have few static variables which shud contain these vaules.  public string TT; public string TT1; public string TextForeColor =sess = "#FFFFFF";   i want to get T value into TT ... T1 into TT1..and so on &n...

getting values from a web form to windows form
Hot Requirement ..... Is there any possible of getting values from a web form to windows form ????? Yes One way i to use the WebRequest and WebResponse classes of the System.Net namespace. For example:  WebRequest request = WebRequest.Create("URL of the web page); WebResponse response = request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string content = reader.ReadLine(); ....    Reza Nassabehwww.professionalcsharp.comDon't forget to click "Mark as Answer" on the post that helped you. That way fut...

how i can get the one form variable values in other forms?????
iam going to pass values of one form to another formlike asfollows.. f1=CType(Context.Handler ,f1);here f1 is form object this will be used in some other form.iam try ing to use to global variables of first form in to second form.while compilation it show s an error like as follws:"The name 'CType' does not exist in the class or namespace 'PassingValuesForms.Form2'can you giv aslo pls..thanks in advance..ramsCheersRam MCP CType is for the VB.NET language exclusively. By adding a semicolon to your code, I'm guessing you are using C#.CType provides VB users with typecasting. In C#, the lang...

Getting value out of session variable
 Hi,How to get the value of a session. It is storing the dataset value. I dont know how to transfer that to a variable.   private SearchDotnet.Searchs.UserSearch sSite;  if ((sSite == null))          {             sSite = Session["Site"];           }         }  The thing is sSite is  delcared as above. I need to unload the session variable to sSite. Have not found a...

getting value of session variable
I'm trying to display the value of a session variable in a label. I know the session variable exists because in my page load event I redirect the user to a different page if it's value is null. I want to display it's value in a label to test some things, but I keep getting an error whenever I try.  Here is my code:   Label:<asp:Label ID="lblSessionTest" runat="server" Text="Label"></asp:Label>  How I'm trying to display it (in my page load event):  lblSessionTest.Text = Session("loggedIn"); &nbs...

Passing Values from a Web Form to Another Web Form
Hello All! I am trying to pass values from one web form to another web form. I know that there are 3 ways of doing this: queryString, Server.Transfer and Session. I am using the Server.Transfer method. But I am not able to create, in my 2nd web form, an instance of my 1st web form. My 1st Web form is named CallTrack.aspx and my 2nd is named Export.aspx. What I mean is something like this: Public value as CallTrack. I can't create it in my 2nd web form because when the intellisense is displayed, there's no CallTrack in the options. Thanks!   How about using cross-...

How to get the HREF value of the Anchor tag in a web page using the web browser control in
Hi Friends,               i have a webserver control in my application.i load the web browser control on a button click using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click                AxWebBrowser1.Navigate("", False) End sub once the page is loaded in the browser i want the <a> HREF value in that page.For example if that page has ...

Get listbox value from the other web form
 Dear all, I want to get the lisbox selecteditem value to a textbox in one web form from the other web page. Should I use session to get this value?Can any one help in this regard? Thanks a lot in advance.  People Develop People Yes you can use Session to get the informations between cross pages.. see below for your referenceTO STORE THE INFO in Session Session["key"] = ListBox1.SelectedItem.Value; Response.Redirect("Page2.aspx");TO GET THE VALUES FROM Sessionprotected void Page_Load(object sender, EventArgs e){    if (Sessio...

Session variable value gets lost
I am using 3.0 with C#. My web application requires some values that is used across my User Controls. These values are pertaining to the login user name and User type. When each user is logged in I store that username and user type in a session variable and whenever i need to used it like in a query I just called the string variable that is assigned to the Session variable. My problem is sometimes my session object/ string variable loses its value and I am wondering is there another way of storing my User's credential so that the value will not be lost until the User closes his/h...

session variables in javascript on a web form
Hi All, I have master page on which I have written a javascript which open ups a new window when user clicks on menu item placed on the left side of master page. The javascript follows  function OpenWind()       {         <% if( HttpContext.Current.Session["Id"]==null) { %>                alert('Session Expired! Redirecting to login page!');           &nb...

Getting a session variable value in Servlet
Hi, I am using psSession to set and get session variables in PowerDynamo scripts. I also had to use servlets for serving some of the pages. I want to access the session variables I have set in PowerDynamo scripts from my servlet. I tried session.getValue from my servlet. But it returns a null in servlet. Any ideas as to how I can get the values of session variables in my servlet? TIA, Mani. Mani, I would think that because they are two different session types you could not do this. A workaround would be to create a cookie that you can use from either spot Scott ...

How to get session variable values in webpart?
Anyone know that how to get session variable values in webpart? I developed a ASP.NET page to accept a input order code e.g. "E923829" and set it as session variable for the following working page. One of the working page is containing a webpart to show this order summary e.g. number of items and total price. I'm using VB.NET to develop this webpart. I'd tried to use Dim OrderNumber as string = Page.session("ORDER_NUMER"). But this will cause error while loading the webpart. Your advice will very appreciated....

Implementing .Net Form into an web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Session variables not pointing to Request.Form Values
I am trying to take the value a user inputs from a form and put it into a session variable.  The basic code (on Page1) is thus:Session("first_name") = Request.Form("first_name")If I reference the session variable on that same page (such as <%= Session("first_name") %>) it works fine.   However, when I go to a new page (Page2) it does not work anymore, the session variable just shows up blank.  If I go back to the first page and set the session variable equal to a simple string it works and will show up fine on both pages.  Like thu...

Web resources about - Session Variables (Get values) -

Variable - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Westpac interest rate rise is one of many variable loan rate rises
WESTPAC is not alone in hitting its owner-occupier customers with a surprise interest rate rise, as dozens of other variable rate home loans ...

Airbnb upgrades variable pricing tool for hosts
Online home rental group Airbnb is rolling out an upgraded variable pricing tool that automatically raises or cuts room rates based on supply ...

Commonwealth Bank raises variable home loan rates
Home owners' mortgage costs are set to rise by hundreds of dollars a year, after the Commonwealth Bank became the latest bank to hike interest ...

CBA lifts variable home loan rates to offset costs associated with stricter capital requirements
The Commonwealth Bank to lift its home loan interest rates independently of the Reserve Bank to partially offset costs associated with stricter ...

Washington Square Signs Spielbergs, Choi Joins Variable and More
... films and an episode of the HBO comedy series "Girls," on which he plays the role of Ray Ploshansky. New York-based creative collective Variable ...

YouTube v10.32 Tweaks Some Interface Elements And Includes Hints About Virtual Reality Content And Variable ...
Forget Update Wednesday! Monday is the new big day. Not only were we treated to the latest M preview release and the official Marshmallow name, ...

"You have to ignore many variables to think women are paid less than men. California is happy to try." ...
Writes Sarah Ketterer in The Wall Street Journal in "The ‘Wage Gap’ Myth That Won’t Die" (which you can get to without subscribing if you Google ...

Staley: 'A lot of different variables...been a hard year'
... 41° Navigation Home Giants A's Sharks Warriors Kings 49ers Raiders Quakes Insiders More Tickets Shop Watch Staley: 'A lot of different variables...been ...

Expert Reveals the Latest Variable Capacity Technology
Learn about gForce Ultra CRAC equipment, the latest variable capacity technology to lower energy usage and increase reliability.

Resources last updated: 12/29/2015 1:31:03 PM