Click here to Skip to main content
13,196,126 members (51,796 online)
Rate this:
 
Please Sign up or sign in to vote.
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 5:13am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Oleksandr Kulchytskyi 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 27-Dec-12 11:38am
   
Thank you kind sir
cs101000 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"]);
<p>@ps.FirstName</p>
Now I get System.NullReferenceException. Its not working.
Adam R Harris 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.
i.e.

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
 
good
Please Sign up or sign in to vote.

Solution 2

Hi,

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...
  Permalink  
v2
Comments
Adam R Harris 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
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.171019.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2017
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