alaa

alaa

  • NA
  • 166
  • 85.2k

send and recive session values between pages

Jul 26 2013 8:30 AM
hi everybody
i want  to pass 10 textboxes values to another page where i can save them in database
i use session to do that this is my code

  ArrayList addinfo = new ArrayList();
        addinfo.Add(Txt1.Text);
        addinfo.Add(Txt2.Text);
        addinfo.Add(Txt3.Text);
       addinfo.Add(Txt4.Text);
        addinfo.Add(Txt5.Text);
        addinfo.Add(Txt6.Text);
        addinfo.Add(Txt7.Text);
        addinfo.Add(Txt8.Text);
        addinfo.Add(Txt9.Text);
       addinfo.Add(Txt10.Text);
   
        Session["addinfoarray"] = addinfo;

Response.Redirect("Confirm.aspx)

on the other page i retrive cookies like this

 ArrayList al2 = (ArrayList)Session["addinfoarray"];
        addinfo.Text = (string)al2[0];
       addinfo1.Text = (string)al2[1];
       addinfo2.Text = (string)al2[2];
         addinfo3.Text = (string)al2[3];
addinfo4.Text = (string)al2[4];
       addinfo5.Text = (string)al2[5];
       addinfo6.Text = (string)al2[6];
         addinfo7.Text = (string)al2[7];
   addinfo8.Text = (string)al2[8];
         addinfo9.Text = (string)al2[9];

it works fine no problem
but i  need to shorten my code using loop like foreach i try to do but no way how can i do it ?? i


Answers (7)