Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi! I have a form in my webpage. The scenario is to transfer a list (of strings)
C#
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

 
Share this answer
 
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>
Hi,

you can send data to other controls via the constructor.

C#
public List<string> myStringList;

//the construtor of you "otherpage"
public MyPage(List<string> sendedStringList)
{
    myStringList = sendedStringList;
}


Best regards...
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900