Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Session array

Session array

Scheduled Pinned Locked Moved ASP.NET
data-structureshelplounge
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sandraa
    wrote on last edited by
    #1

    Hi all, somebody knows how create a array multi-dimensional with session variables. I have it:

    Session("Preguntas") = LPH.ObtenerTest(Session("Articulo"), Session("Nivel"))

    where it session is a table and I want to add the result of client into other session array but with 2 columns, something similar to

    Session("ArrayRespuestas")(Session("i"), 1) = "1"

    . I use session variable because when the user make click into button I receive a postback and lost my original select (LPH.ObtenerTest(Session("Articulo"), Session("Nivel"))) that is a procedure that return a select random with 2 parameters. If I use

    If Not Me.Page.IsPostBack Then

    and put my select into later (the second page_load) doesn't load my select and when I call to

    Preguntas.Rows(i)("Respuesta1")

    I received a error where told me that I must first create a object. Thanks for all.

    R 1 Reply Last reply
    0
    • S Sandraa

      Hi all, somebody knows how create a array multi-dimensional with session variables. I have it:

      Session("Preguntas") = LPH.ObtenerTest(Session("Articulo"), Session("Nivel"))

      where it session is a table and I want to add the result of client into other session array but with 2 columns, something similar to

      Session("ArrayRespuestas")(Session("i"), 1) = "1"

      . I use session variable because when the user make click into button I receive a postback and lost my original select (LPH.ObtenerTest(Session("Articulo"), Session("Nivel"))) that is a procedure that return a select random with 2 parameters. If I use

      If Not Me.Page.IsPostBack Then

      and put my select into later (the second page_load) doesn't load my select and when I call to

      Preguntas.Rows(i)("Respuesta1")

      I received a error where told me that I must first create a object. Thanks for all.

      R Offline
      R Offline
      Ranjit Viswakumar
      wrote on last edited by
      #2

      The below code allows a multi-dimensional array to be stored in the session state. See if you can adapt this to fit your use. Good luck.

      private void StoreToSession()
      {
      string[,]initialArray={"A","B"};
      Session["sessionvalue"]=initialArray;
      }

      private void ReteriveFromSession()
      {
      string[,]resultantArray=(string[,])Session["sessionvalue"];
      TextBox1.Text=resultantArray[0,0].ToString();
      TextBox2.Text=resultantArray[0,1].ToString();
      }

      Ranjit Viswakumar Professional Services Specialist http://hostmysite.com/?utm\_source=bb

      S 1 Reply Last reply
      0
      • R Ranjit Viswakumar

        The below code allows a multi-dimensional array to be stored in the session state. See if you can adapt this to fit your use. Good luck.

        private void StoreToSession()
        {
        string[,]initialArray={"A","B"};
        Session["sessionvalue"]=initialArray;
        }

        private void ReteriveFromSession()
        {
        string[,]resultantArray=(string[,])Session["sessionvalue"];
        TextBox1.Text=resultantArray[0,0].ToString();
        TextBox2.Text=resultantArray[0,1].ToString();
        }

        Ranjit Viswakumar Professional Services Specialist http://hostmysite.com/?utm\_source=bb

        S Offline
        S Offline
        Sandraa
        wrote on last edited by
        #3

        Doesn't work because the postback empty my array when I push btton. I have when load the first ask (is a test of 25 ask):

        Public Ar1(25, 1) As Integer

        Procedure of load ask

                        Ar1(Session("i"), 0) = Session("Preguntas").Rows(Session("i"))("Id\_Pregunta")
                        Session("ArrayRespuestas") = Ar1
        

        later when button_onclick:

        Dim respuesta As Integer
        If RadioButton1.Checked = True Then respuesta = 1
        If RadioButton2.Checked = True Then respuesta = 2
        If RadioButton3.Checked = True Then respuesta = 3
        If RadioButton4.Checked = True Then respuesta = 4
        If RadioButton5.Checked = True Then respuesta = 5
        Ar1(Session("i"), 1) = respuesta
        Session("ArrayRespuestas") = Ar1
        Session("i") = Session("i") + 1

        This work without errors, but when I try to recovery the datas of array I only get the value present Ar1(Session("i"), 1) but I lost the value Ar1(Session("i"), 0) because was added before of push button and later the postback empty my array. Good, realty is when I put Session("ArrayRespuestas") = Ar1 is when I clear my session array. I believe that the solve is to search like get not postback when click button. I accept advisers boys :)

        S 1 Reply Last reply
        0
        • S Sandraa

          Doesn't work because the postback empty my array when I push btton. I have when load the first ask (is a test of 25 ask):

          Public Ar1(25, 1) As Integer

          Procedure of load ask

                          Ar1(Session("i"), 0) = Session("Preguntas").Rows(Session("i"))("Id\_Pregunta")
                          Session("ArrayRespuestas") = Ar1
          

          later when button_onclick:

          Dim respuesta As Integer
          If RadioButton1.Checked = True Then respuesta = 1
          If RadioButton2.Checked = True Then respuesta = 2
          If RadioButton3.Checked = True Then respuesta = 3
          If RadioButton4.Checked = True Then respuesta = 4
          If RadioButton5.Checked = True Then respuesta = 5
          Ar1(Session("i"), 1) = respuesta
          Session("ArrayRespuestas") = Ar1
          Session("i") = Session("i") + 1

          This work without errors, but when I try to recovery the datas of array I only get the value present Ar1(Session("i"), 1) but I lost the value Ar1(Session("i"), 0) because was added before of push button and later the postback empty my array. Good, realty is when I put Session("ArrayRespuestas") = Ar1 is when I clear my session array. I believe that the solve is to search like get not postback when click button. I accept advisers boys :)

          S Offline
          S Offline
          Sandraa
          wrote on last edited by
          #4

          Solved I put into page_load

              If Not Me.Page.IsPostBack Then
                  Session("i") = 0
                  Dim Ar1(25, 1) As Integer
                  Session("ArrayRespuestas") = Ar1
              End If
          

          Then only I define the array a time :) Thanks for your help ;-)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups