Re: Muliple Users aspx project

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: John Saunders (johnwsaundersiii)
Date: 12/11/04


Date: Sat, 11 Dec 2004 16:08:27 -0500


<grizduck@comcast.net> wrote in message
news:1102797107.968088.215990@z14g2000cwz.googlegroups.com...
> so, on webform1 I can "declare" the variable like this
>
> session("FirstName") = txtfirstname.text
>
> and then display it on , say, page 4 with
>
> lblfirstname.text = session("FirstName")?
>
> also, can you calculate with these variables like
>
> session("Subtotal") = session("Integer1") * session("Integer2")?

No, because "*" is not a valid operator for the Object type.

You'll need

Session("Subtotal") = DirectCast(Session("Integer1"), Integer) *
DirectCast(Session("Integer2"), Integer)

You _are_ running with Options Strict On, aren't you?

John Saunders

> Thanks again
> John Saunders wrote:
>> <grizduck@comcast.net> wrote in message
>> news:1102755030.897956.181340@f14g2000cwb.googlegroups.com...
>> > This is very helpful. I have one question though. Where do i
> declare
>> > the session variables? Since I ran into this problem, I have been
>> > reading many groups and researching the problem. Do I declare the
>> > variables in global.asax or on each webform? Thanks in advance.
>>
>> You don't have to declare them at all. They're not "variables",
> really.
>>
>> "Session" (aka Page.Session, or Page.Context.Session) is an instance
> of the
>> HttpSessionState class. You can treat it as a collection of
> name-value
>> pairs. You can set a value with syntax like
>>
>> Session("FirstName") = TheFirstNameValue
>>
>> and then you can retrieve it with
>>
>> Dim o As Object = Session("FirstName")
>>
>> Note that Session(string) returns an Object, so you'll have to cast
> it to
>> the correct type:
>>
>> Dim s As String = DirectCast(Session("FirstName"), String)
>>
>> Note the use of DirectCast, which is correct since you know that it's
> a
>> string (you put it there, after all). Do not use CType or ToString in
> these
>> cases, as though you didn't know what type of value you put there.
>>
>> Note also that this is subject to spelling errors -
> Session("FirstNam") will
>> return Nothing. I usually solve this problem by wrapping session
> state in a
>> class and using properties of the class to access it:
>>
>> Public Class UserState
>> ...
>> Public Shared Property FirstName As String
>> Get
>> Return
> DirectCast(HttpContext.Current.Session("FirstName"),
>> String)
>> End Get
>> Set(ByVal Value As String)
>> HttpContext.Current.Session("FirstName") = Value
>> End Set
>> End Property
>> ...
>> End Class
>>
>> This way, there are only two places for a typo to happen. I would
> access
>> this from a page as UserState.FirstName. This can be accessed from
> multiple
>> pages.
>>
>> BTW, Note the use of HttpContext.Current.Session. Since class
> UserState
>> isn't a Page, it doesn't have a "Session" member, so the Shared
> HttpContext
>> member "Current" is used to access the current request context.
>>
>>
>> John Saunders
>



Relevant Pages

  • ANN: MeObjects Library for Delphi
    ... object type small and powerful. ... the Object instance can use the ClassType method return the ... Especially for lists of pointers to dynamically allocated memory. ... {Summary Adds Ansi String and correspondent object to a list. ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: SCJP Question - Polymorphism, method overloading, overridding
    ... object type is considered, when overloading the reference type is ... Others have already explained the reason, but I want to add that overloading is not operative in this particular situation. ... The expression in question is ruled by the variable at compile time; that's why it delivers an error. ... String s = thing.method1; ...
    (comp.lang.java.help)
  • Re: Transferring data to heterogeneous clients
    ... John Saunders [MVP] ... Public FirstName As String ... Participant class at runtime based on column structure of a DataTable. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: VBA.convertFromJava("instanceof")=?
    ... TypeOf is better than TypeName because you can prefix a typelib to the object type to ensure that you have the right object type. ... both the Excel and the MSForms libraries have an object named CheckBox. ... you will get only the string "CheckBox" as the result. ...
    (microsoft.public.excel.programming)
  • Re: ASP and session object (get type)
    ... Head of Development ... Integrity eLearning ... > contains (for example, determine whether it is a string, integer, single ... > Is there any easy way to detect the object type in ASP? ...
    (microsoft.public.inetserver.asp.general)