-1
private void btnback1_Click(object sender, EventArgs e)
{
    firstpage first = new firstpage();
    first.Show();

    this.Hide();
}

I tried this way of redirecting but when i pressed back,the stuff that I typed (in previous page)is all gone.

Kevin Brechbühl
  • 4,717
  • 3
  • 24
  • 47
  • You can use `Response.Redirect();` – Shreyas Achar Feb 04 '14 at 09:57
  • 3
    @ShreyasTg - this might be windows forms not web ... – Pranay Rana Feb 04 '14 at 09:57
  • There is no such thing as "page" in windows forms. We might be understanding you correctly, but just in case, please, explain what page means for you. Are you paging some data? Or are you calling Form the wrong name? What's the intent behind those pages of yours? Is it really necessary to create a new form when you "change pages"? Is the "new page" the same form as the "old page"? – Luaan Feb 04 '14 at 10:03
  • your `firstpage first = new firstpage();` is creating a new instance of `firstpage`, which will mean you will lose all your values. Looking at your code, your just hiding and showing a panel (or similar), you won't need to make a new instance, just use `.hide()` and `.show` ? – JustAnotherDeveloper Feb 04 '14 at 10:26

2 Answers2

1

The problem is that you are creating the new object of the first page and then making it show.

So the solution is

Solution 1: If possible maintain the object of the first page.

or

Solution 2: If possible assign value to all the controls again after creating page.

Jens H
  • 4,590
  • 2
  • 25
  • 35
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
  • For a beginner questions like this a better answer is required, i.e a snippet of what is *maintain the object of the first page* and concept of *assign value again*. – Sinatr Feb 04 '14 at 10:40
0

You have firstpage first = new firstpage();, which initializes a new instance with default values. This is why you are not getting your old values back. I would advise you to keep your values stored somewhere (a global singleton or something) so you can set them again, or keep a reference to the first page somewhere and call it's Show() method instead of creating a new one. Both ways have pros and cons, but it's up to you to choose which one you will use.

Mario Stoilov
  • 3,411
  • 5
  • 31
  • 51