Session Arrays

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

    Session Arrays

    Hello!

    I have a simple question.

    Do we have session arrays that we can reference, assign, or select from?

    Could I please have a sample of how this is done. The obvious syntax that I
    am trying doesn't work. There are SA's in VB, but I am not seeing anything
    for C#.

    Thank you!

    -Bahman
  • Siva M

    #2
    Re: Session Arrays

    Not sure if you are talking about the Session object. If so, in C#, we use
    square brackets ([]) to access the session collection as in
    Session["mykey"].

    HTH

    "Bahman" <Bahman@discuss ions.microsoft. com> wrote in message
    news:A07CD54B-0949-4217-B15D-CED0612CD4A8@mi crosoft.com...
    Hello!

    I have a simple question.

    Do we have session arrays that we can reference, assign, or select from?

    Could I please have a sample of how this is done. The obvious syntax that I
    am trying doesn't work. There are SA's in VB, but I am not seeing anything
    for C#.

    Thank you!

    -Bahman


    Comment

    • Karl Seguin

      #3
      Re: Session Arrays

      Perhaps if you showed us what syntax you were using that doesn't work, we
      could be of more help.

      I'm not sure what you mean by "session arrays"

      In ASP.Net you have a session which you can access in c# such as:

      Session["SomeUserId "] = 1;

      Karl

      --
      MY ASP.Net tutorials
      http://www.openmymind.net/ - New and Improved (yes, the popup is
      annoying)
      http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
      come!)
      "Bahman" <Bahman@discuss ions.microsoft. com> wrote in message
      news:A07CD54B-0949-4217-B15D-CED0612CD4A8@mi crosoft.com...[color=blue]
      > Hello!
      >
      > I have a simple question.
      >
      > Do we have session arrays that we can reference, assign, or select from?
      >
      > Could I please have a sample of how this is done. The obvious syntax that
      > I
      > am trying doesn't work. There are SA's in VB, but I am not seeing anything
      > for C#.
      >
      > Thank you!
      >
      > -Bahman[/color]


      Comment

      • Bahman

        #4
        Re: Session Arrays

        Karl,

        In VB, you can say

        session("array" ) (1) = "1"
        session("array" ) (2) = "2"

        In other words, the session object can be assigned a type other than the
        basic types of numbers and strings, in this case an array.

        I wonder if that can be done in c#. Obviously, I wouldn't know how to define
        it since we don't explicity define session objects, I would think.

        The syntax wouldn't need to be the same. For example, if I could create an
        array, assign it to some kind of session object, create another array, and
        assing the session object back to the other array, that would work too. I
        wouldn't need the session variable itself to work like an array. But it would
        be nice.

        Also, all I am trying to do is use the array on a different page. If I can
        make the array somehow persistent in some other way, that would be very ok as
        well.

        -Bahman

        "Karl Seguin" wrote:
        [color=blue]
        > Perhaps if you showed us what syntax you were using that doesn't work, we
        > could be of more help.
        >
        > I'm not sure what you mean by "session arrays"
        >
        > In ASP.Net you have a session which you can access in c# such as:
        >
        > Session["SomeUserId "] = 1;
        >
        > Karl
        >
        > --
        > MY ASP.Net tutorials
        > http://www.openmymind.net/ - New and Improved (yes, the popup is
        > annoying)
        > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
        > come!)
        > "Bahman" <Bahman@discuss ions.microsoft. com> wrote in message
        > news:A07CD54B-0949-4217-B15D-CED0612CD4A8@mi crosoft.com...[color=green]
        > > Hello!
        > >
        > > I have a simple question.
        > >
        > > Do we have session arrays that we can reference, assign, or select from?
        > >
        > > Could I please have a sample of how this is done. The obvious syntax that
        > > I
        > > am trying doesn't work. There are SA's in VB, but I am not seeing anything
        > > for C#.
        > >
        > > Thank you!
        > >
        > > -Bahman[/color]
        >
        >
        >[/color]

        Comment

        • Marina

          #5
          Re: Session Arrays

          The only reason VB let's you do that, is because you have Option Strict Off.
          Turn it on, and you will get a compile time error.

          Always use option strict On, when you are using VB.

          In either case (VB with option strict on, or C#), you need to case
          session("array" ) to an array of whatever type is appropriate, and only then
          can you access a particular item in the array.

          "Bahman" <Bahman@discuss ions.microsoft. com> wrote in message
          news:1385DB73-072E-4E62-836D-75F52C13CE70@mi crosoft.com...[color=blue]
          > Karl,
          >
          > In VB, you can say
          >
          > session("array" ) (1) = "1"
          > session("array" ) (2) = "2"
          >
          > In other words, the session object can be assigned a type other than the
          > basic types of numbers and strings, in this case an array.
          >
          > I wonder if that can be done in c#. Obviously, I wouldn't know how to
          > define
          > it since we don't explicity define session objects, I would think.
          >
          > The syntax wouldn't need to be the same. For example, if I could create an
          > array, assign it to some kind of session object, create another array, and
          > assing the session object back to the other array, that would work too. I
          > wouldn't need the session variable itself to work like an array. But it
          > would
          > be nice.
          >
          > Also, all I am trying to do is use the array on a different page. If I can
          > make the array somehow persistent in some other way, that would be very ok
          > as
          > well.
          >
          > -Bahman
          >
          > "Karl Seguin" wrote:
          >[color=green]
          >> Perhaps if you showed us what syntax you were using that doesn't work, we
          >> could be of more help.
          >>
          >> I'm not sure what you mean by "session arrays"
          >>
          >> In ASP.Net you have a session which you can access in c# such as:
          >>
          >> Session["SomeUserId "] = 1;
          >>
          >> Karl
          >>
          >> --
          >> MY ASP.Net tutorials
          >> http://www.openmymind.net/ - New and Improved (yes, the popup is
          >> annoying)
          >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
          >> come!)
          >> "Bahman" <Bahman@discuss ions.microsoft. com> wrote in message
          >> news:A07CD54B-0949-4217-B15D-CED0612CD4A8@mi crosoft.com...[color=darkred]
          >> > Hello!
          >> >
          >> > I have a simple question.
          >> >
          >> > Do we have session arrays that we can reference, assign, or select
          >> > from?
          >> >
          >> > Could I please have a sample of how this is done. The obvious syntax
          >> > that
          >> > I
          >> > am trying doesn't work. There are SA's in VB, but I am not seeing
          >> > anything
          >> > for C#.
          >> >
          >> > Thank you!
          >> >
          >> > -Bahman[/color]
          >>
          >>
          >>[/color][/color]


          Comment

          • Bahman

            #6
            Re: Session Arrays

            Marina,

            This is outstanding.

            I only have one question for you.

            How do I 'case' a session variable to become an array in c#?

            Could you please point me to a page or site with samples or definitions?

            Thank you very much for your help!

            -Bahman

            "Marina" wrote:
            [color=blue]
            > The only reason VB let's you do that, is because you have Option Strict Off.
            > Turn it on, and you will get a compile time error.
            >
            > Always use option strict On, when you are using VB.
            >
            > In either case (VB with option strict on, or C#), you need to case
            > session("array" ) to an array of whatever type is appropriate, and only then
            > can you access a particular item in the array.
            >
            > "Bahman" <Bahman@discuss ions.microsoft. com> wrote in message
            > news:1385DB73-072E-4E62-836D-75F52C13CE70@mi crosoft.com...[color=green]
            > > Karl,
            > >
            > > In VB, you can say
            > >
            > > session("array" ) (1) = "1"
            > > session("array" ) (2) = "2"
            > >
            > > In other words, the session object can be assigned a type other than the
            > > basic types of numbers and strings, in this case an array.
            > >
            > > I wonder if that can be done in c#. Obviously, I wouldn't know how to
            > > define
            > > it since we don't explicity define session objects, I would think.
            > >
            > > The syntax wouldn't need to be the same. For example, if I could create an
            > > array, assign it to some kind of session object, create another array, and
            > > assing the session object back to the other array, that would work too. I
            > > wouldn't need the session variable itself to work like an array. But it
            > > would
            > > be nice.
            > >
            > > Also, all I am trying to do is use the array on a different page. If I can
            > > make the array somehow persistent in some other way, that would be very ok
            > > as
            > > well.
            > >
            > > -Bahman
            > >
            > > "Karl Seguin" wrote:
            > >[color=darkred]
            > >> Perhaps if you showed us what syntax you were using that doesn't work, we
            > >> could be of more help.
            > >>
            > >> I'm not sure what you mean by "session arrays"
            > >>
            > >> In ASP.Net you have a session which you can access in c# such as:
            > >>
            > >> Session["SomeUserId "] = 1;
            > >>
            > >> Karl
            > >>
            > >> --
            > >> MY ASP.Net tutorials
            > >> http://www.openmymind.net/ - New and Improved (yes, the popup is
            > >> annoying)
            > >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
            > >> come!)
            > >> "Bahman" <Bahman@discuss ions.microsoft. com> wrote in message
            > >> news:A07CD54B-0949-4217-B15D-CED0612CD4A8@mi crosoft.com...
            > >> > Hello!
            > >> >
            > >> > I have a simple question.
            > >> >
            > >> > Do we have session arrays that we can reference, assign, or select
            > >> > from?
            > >> >
            > >> > Could I please have a sample of how this is done. The obvious syntax
            > >> > that
            > >> > I
            > >> > am trying doesn't work. There are SA's in VB, but I am not seeing
            > >> > anything
            > >> > for C#.
            > >> >
            > >> > Thank you!
            > >> >
            > >> > -Bahman
            > >>
            > >>
            > >>[/color][/color]
            >
            >
            >[/color]

            Comment

            • Karl Seguin

              #7
              Re: Session Arrays

              string[] cough = (string[])Session["SomeArrayK ey"];

              --
              MY ASP.Net tutorials
              http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
              http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
              come!)


              "Bahman" <Bahman@discuss ions.microsoft. com> wrote in message
              news:37843D8B-03D1-4315-82F1-250976314CD6@mi crosoft.com...[color=blue]
              > Marina,
              >
              > This is outstanding.
              >
              > I only have one question for you.
              >
              > How do I 'case' a session variable to become an array in c#?
              >
              > Could you please point me to a page or site with samples or definitions?
              >
              > Thank you very much for your help!
              >
              > -Bahman
              >
              > "Marina" wrote:
              >[color=green]
              >> The only reason VB let's you do that, is because you have Option Strict
              >> Off.
              >> Turn it on, and you will get a compile time error.
              >>
              >> Always use option strict On, when you are using VB.
              >>
              >> In either case (VB with option strict on, or C#), you need to case
              >> session("array" ) to an array of whatever type is appropriate, and only
              >> then
              >> can you access a particular item in the array.
              >>
              >> "Bahman" <Bahman@discuss ions.microsoft. com> wrote in message
              >> news:1385DB73-072E-4E62-836D-75F52C13CE70@mi crosoft.com...[color=darkred]
              >> > Karl,
              >> >
              >> > In VB, you can say
              >> >
              >> > session("array" ) (1) = "1"
              >> > session("array" ) (2) = "2"
              >> >
              >> > In other words, the session object can be assigned a type other than
              >> > the
              >> > basic types of numbers and strings, in this case an array.
              >> >
              >> > I wonder if that can be done in c#. Obviously, I wouldn't know how to
              >> > define
              >> > it since we don't explicity define session objects, I would think.
              >> >
              >> > The syntax wouldn't need to be the same. For example, if I could create
              >> > an
              >> > array, assign it to some kind of session object, create another array,
              >> > and
              >> > assing the session object back to the other array, that would work too.
              >> > I
              >> > wouldn't need the session variable itself to work like an array. But it
              >> > would
              >> > be nice.
              >> >
              >> > Also, all I am trying to do is use the array on a different page. If I
              >> > can
              >> > make the array somehow persistent in some other way, that would be very
              >> > ok
              >> > as
              >> > well.
              >> >
              >> > -Bahman
              >> >
              >> > "Karl Seguin" wrote:
              >> >
              >> >> Perhaps if you showed us what syntax you were using that doesn't work,
              >> >> we
              >> >> could be of more help.
              >> >>
              >> >> I'm not sure what you mean by "session arrays"
              >> >>
              >> >> In ASP.Net you have a session which you can access in c# such as:
              >> >>
              >> >> Session["SomeUserId "] = 1;
              >> >>
              >> >> Karl
              >> >>
              >> >> --
              >> >> MY ASP.Net tutorials
              >> >> http://www.openmymind.net/ - New and Improved (yes, the popup is
              >> >> annoying)
              >> >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
              >> >> come!)
              >> >> "Bahman" <Bahman@discuss ions.microsoft. com> wrote in message
              >> >> news:A07CD54B-0949-4217-B15D-CED0612CD4A8@mi crosoft.com...
              >> >> > Hello!
              >> >> >
              >> >> > I have a simple question.
              >> >> >
              >> >> > Do we have session arrays that we can reference, assign, or select
              >> >> > from?
              >> >> >
              >> >> > Could I please have a sample of how this is done. The obvious
              >> >> > syntax
              >> >> > that
              >> >> > I
              >> >> > am trying doesn't work. There are SA's in VB, but I am not seeing
              >> >> > anything
              >> >> > for C#.
              >> >> >
              >> >> > Thank you!
              >> >> >
              >> >> > -Bahman
              >> >>
              >> >>
              >> >>[/color]
              >>
              >>
              >>[/color][/color]


              Comment

              Working...