Variable & storing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yop

    #1

    Variable & storing

    Hello

    I have an application, Login page, enter UserName &
    Password.
    Function in Users called GetUserDetails and checks the
    details and if they are valid calls a function to fill
    the following in the class component called

    Public Class UserDetails
    Public UserID As Integer
    Public UserName As String
    Public FullName As String
    Public Email As String
    End Class

    So I would have thought now that what ever page I goto
    that I could retreive the email or fullname from the
    class above without having the call the GetUserDetails.

    I use the following code.

    'Load the User Name textbox
    Dim userDetails As New
    ASPNET.ASSETREG ISTER.UserDetai ls()
    msgfullname.Tex t = " Logged In: " &
    userDetails.Ful lName

    But it does not fill it, any ideas?
    thanks in advance
  • Cowboy \(Gregory A. Beamer\)

    #2
    Re: Variable & storing

    Once you fill the object, where are you storing it? In session? Serialized
    to disk? Not at all?

    Since you are simply creating a group of properties/fields a struct might be
    a better option, but you still have to store it:

    Dim MyClass As UserDetails = new UserDetails()
    'lines to fill class here
    Session("MyClas s") = MyClass

    To use:
    Dim MyClass as UserDetails = CType(Session(" MyClass"), MyClass)

    You could make a static class to hold the variables, but you could only have
    one user at a time. Then, your code would work without saving the object
    off.

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA
    Author: ADO.NET and XML: ASP.NET on the Edge

    *************** *************** *************** *************** *************** *
    ****
    Think Outside the Box!
    *************** *************** *************** *************** *************** *
    ****
    "yop" <aidangill@ocea nfree.net> wrote in message
    news:065101c352 87$2bb01b10$a60 1280a@phx.gbl.. .[color=blue]
    > Hello
    >
    > I have an application, Login page, enter UserName &
    > Password.
    > Function in Users called GetUserDetails and checks the
    > details and if they are valid calls a function to fill
    > the following in the class component called
    >
    > Public Class UserDetails
    > Public UserID As Integer
    > Public UserName As String
    > Public FullName As String
    > Public Email As String
    > End Class
    >
    > So I would have thought now that what ever page I goto
    > that I could retreive the email or fullname from the
    > class above without having the call the GetUserDetails.
    >
    > I use the following code.
    >
    > 'Load the User Name textbox
    > Dim userDetails As New
    > ASPNET.ASSETREG ISTER.UserDetai ls()
    > msgfullname.Tex t = " Logged In: " &
    > userDetails.Ful lName
    >
    > But it does not fill it, any ideas?
    > thanks in advance[/color]


    Comment

    • yop

      #3
      Re: Variable &amp; storing

      Ok to be honest I am not sure where they are stored, in
      the class.
      The class is not been stored in the session. I do not
      realise that you could to be honest

      thanks

      [color=blue]
      >-----Original Message-----
      >Once you fill the object, where are you storing it? In[/color]
      session? Serialized[color=blue]
      >to disk? Not at all?
      >
      >Since you are simply creating a group of[/color]
      properties/fields a struct might be[color=blue]
      >a better option, but you still have to store it:
      >
      >Dim MyClass As UserDetails = new UserDetails()
      >'lines to fill class here
      >Session("MyCla ss") = MyClass
      >
      >To use:
      >Dim MyClass as UserDetails = CType(Session(" MyClass"),[/color]
      MyClass)[color=blue]
      >
      >You could make a static class to hold the variables, but[/color]
      you could only have[color=blue]
      >one user at a time. Then, your code would work without[/color]
      saving the object[color=blue]
      >off.
      >
      >--
      >Gregory A. Beamer
      >MVP; MCP: +I, SE, SD, DBA
      >Author: ADO.NET and XML: ASP.NET on the Edge
      >
      >************** *************** *************** *************[/color]
      *************** ****[color=blue]
      >****
      >Think Outside the Box!
      >************** *************** *************** *************[/color]
      *************** ****[color=blue]
      >****
      >"yop" <aidangill@ocea nfree.net> wrote in message
      >news:065101c35 287$2bb01b10$a6 01280a@phx.gbl. ..[color=green]
      >> Hello
      >>
      >> I have an application, Login page, enter UserName &
      >> Password.
      >> Function in Users called GetUserDetails and checks the
      >> details and if they are valid calls a function to fill
      >> the following in the class component called
      >>
      >> Public Class UserDetails
      >> Public UserID As Integer
      >> Public UserName As String
      >> Public FullName As String
      >> Public Email As String
      >> End Class
      >>
      >> So I would have thought now that what ever page I goto
      >> that I could retreive the email or fullname from the
      >> class above without having the call the GetUserDetails.
      >>
      >> I use the following code.
      >>
      >> 'Load the User Name textbox
      >> Dim userDetails As New
      >> ASPNET.ASSETREG ISTER.UserDetai ls()
      >> msgfullname.Tex t = " Logged In: " &
      >> userDetails.Ful lName
      >>
      >> But it does not fill it, any ideas?
      >> thanks in advance[/color]
      >
      >
      >.
      >[/color]

      Comment

      • Cowboy \(Gregory A. Beamer\)

        #4
        Re: Variable &amp; storing

        When you load a class, it goes out of scope as soon as the page finishes
        processing. If you try to pull that class on another page, it has no values,
        as it is a new instance.

        If you want to use an object across multiple pages, you need to store it
        somewhere. Using Session is the easiest method, but you can serialize the
        object and create your own engine, if there is some reason session is
        unusable. Recreating the wheel is a pain, however, so I would stick to
        Session before rewriting the mechanism.

        --
        Gregory A. Beamer
        MVP; MCP: +I, SE, SD, DBA
        Author: ADO.NET and XML: ASP.NET on the Edge

        *************** *************** *************** *************** *************** *
        ****
        Think Outside the Box!
        *************** *************** *************** *************** *************** *
        ****
        "yop" <aidangill@ocea nfree.net> wrote in message
        news:0bc201c352 b8$ab1eac00$a30 1280a@phx.gbl.. .[color=blue]
        > Ok to be honest I am not sure where they are stored, in
        > the class.
        > The class is not been stored in the session. I do not
        > realise that you could to be honest
        >
        > thanks
        >
        >[color=green]
        > >-----Original Message-----
        > >Once you fill the object, where are you storing it? In[/color]
        > session? Serialized[color=green]
        > >to disk? Not at all?
        > >
        > >Since you are simply creating a group of[/color]
        > properties/fields a struct might be[color=green]
        > >a better option, but you still have to store it:
        > >
        > >Dim MyClass As UserDetails = new UserDetails()
        > >'lines to fill class here
        > >Session("MyCla ss") = MyClass
        > >
        > >To use:
        > >Dim MyClass as UserDetails = CType(Session(" MyClass"),[/color]
        > MyClass)[color=green]
        > >
        > >You could make a static class to hold the variables, but[/color]
        > you could only have[color=green]
        > >one user at a time. Then, your code would work without[/color]
        > saving the object[color=green]
        > >off.
        > >
        > >--
        > >Gregory A. Beamer
        > >MVP; MCP: +I, SE, SD, DBA
        > >Author: ADO.NET and XML: ASP.NET on the Edge
        > >
        > >************** *************** *************** *************[/color]
        > *************** ****[color=green]
        > >****
        > >Think Outside the Box!
        > >************** *************** *************** *************[/color]
        > *************** ****[color=green]
        > >****
        > >"yop" <aidangill@ocea nfree.net> wrote in message
        > >news:065101c35 287$2bb01b10$a6 01280a@phx.gbl. ..[color=darkred]
        > >> Hello
        > >>
        > >> I have an application, Login page, enter UserName &
        > >> Password.
        > >> Function in Users called GetUserDetails and checks the
        > >> details and if they are valid calls a function to fill
        > >> the following in the class component called
        > >>
        > >> Public Class UserDetails
        > >> Public UserID As Integer
        > >> Public UserName As String
        > >> Public FullName As String
        > >> Public Email As String
        > >> End Class
        > >>
        > >> So I would have thought now that what ever page I goto
        > >> that I could retreive the email or fullname from the
        > >> class above without having the call the GetUserDetails.
        > >>
        > >> I use the following code.
        > >>
        > >> 'Load the User Name textbox
        > >> Dim userDetails As New
        > >> ASPNET.ASSETREG ISTER.UserDetai ls()
        > >> msgfullname.Tex t = " Logged In: " &
        > >> userDetails.Ful lName
        > >>
        > >> But it does not fill it, any ideas?
        > >> thanks in advance[/color]
        > >
        > >
        > >.
        > >[/color][/color]


        Comment

        Working...