I have a page where a instructor inserts a student’s id into a text box and then submits it. It should then come up with a list of all the students that have been added. But every time the submit button is pressed, the list gets cleared and only the last student added is displayed.
public Service1Client ws = new Service1Client();
public string adress;
public List<ServiceReference1.User> lu;
protected void Page_Load(object sender, EventArgs e)
{
if (lu==null)
lu= new List<ServiceReference1.User>();
}
protected void Button1_Click(object sender, EventArgs e)
{
ServiceReference1.User u= new ServiceReference1.User();
u = ws.ShowUser(int.Parse(TextBox2.Text));
if (!IsContained(u))
{
lu.Add(u);
TextBox1.Text += u.FirstName;
}
}
Is there a way to solve this? Or must I send the information to the page via a query string?
Each HTTP request gets a new instance of your page.
You should store the list in ViewState to persist across requests.