Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET HTML Webmatrix
Hi! I have a form in my webpage. The scenario is to transfer a list (of strings)
List<string> myLIst= new List<string>();
in the current page to another page when the form's submit button is clicked and the user is redirected to that other page. How can this be done?
Posted 27-Dec-12 6:13am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Oleksandr Kulchytskyi at 27-Dec-12 11:34am
Yep fully agree with you, Session state is one of the most suitable solution for it. My five to U.
Adam R Harris at 27-Dec-12 11:38am
Thank you kind sir
cs101000 at 1-Jan-13 3:18am
Thanks a lot for the help. And what about a user-defined class? I tried to do this:
public class Person
public string FirstName{ get; set; }
public string LastName{ get; set; }
public Person(string strFirst, string strLast)
FirstName = strFirst;
LastName = strLast;
I put this in source page:
Person p1 = new Person("first", "last");
Session["p1"] = p1;
And in target page:
Person ps = (Person)(Session["p1"]);
Now I get System.NullReferenceException. Its not working.
Adam R Harris at 2-Jan-13 9:53am
Without seeing the entire project i can only speculate that your issue is regarding when you pull your person object out of the session state.
The easiest way to get around that is to create a readonlt property that gets the Person object from the session and use that to access your object.
public Person MyPerson {
get { return (Session["p1"] != null ? (Person)Session["Person"] : new Person("","")); }
Then in your page you can just access it like this <p><%=MyPerson.FirstName %></p>
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

you can send data to other controls via the constructor.
public List<string> myStringList;
//the construtor of you "otherpage"
public MyPage(List<string> sendedStringList)
    myStringList = sendedStringList;
Best regards...
Adam R Harris at 27-Dec-12 11:35am
Cool, so how would he redirect to that page passing in the values for the constructor?
Not trying to be a d!ck i am seriously interested in knowing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 385
1 DamithSL 210
2 Kornfeld Eliyahu Peter 210
3 OriginalGriff 180
4 Peter Leow 95
0 OriginalGriff 7,215
1 DamithSL 5,199
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,757
4 Kornfeld Eliyahu Peter 4,514

Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100