0

I have an asp.net mvc5 web application which has 5 pages. The information on the last three pages are passed from the first two. So it’s like my first two pages are dynamic and last three changes according to the first two.
My program is only doing the following thing
I fill information in first page, hit submit button via post request, fill information in second page and hit submit button from second page. The rest pages display the result only.
But the problem arises when I press back button from browser form second page, change some value in first page and press submit button, I lose all the data from the second page. I want the second page retain its state whatever it was before.
I really don’t know how hard it is. So can some please advise me how to resolve that problem? Thanks in advance.Here is just Sample code to illustrate This is the second page

<form action="thirdpage.cshtml" method="post">
          MARKET VALUE OF HOUSE 2nd page:
         <input id="MVOH" type="number" step="any" name="MVH" /><br/><br/>
             
           MORTGAGE OWING 2nd page:
           <input id="MO" type="number" step="any" name="MOwing" /><br/><br/>
            MORTGAGE REPAYMENT 2nd page
            <input id="MPPM" type="number" name="MP" />
            <select id="Sel">
                 <option value="0">Per week</option>
                  <option value="1">Per fortnight</option>
                   <option value="2">Per Month</option>
              </select><br/><br/>
            <div>  
              
              <input id="next" type="submit" value="Income Expenses &raquo;"/>   
          </div>  
   </form>

And the first page is

 <form action="secondpage.cshtml" method="post">
           
            
                   MARKET VALUE OF HOUSE:
                    <input id="MVOH" type="number" step="any" name="MVH" /><br/><br/>
             
                    MORTGAGE OWING:
                    <input id="MO" type="number" step="any" name="MOwing" /><br/><br/>
                    <td>MORTGAGE REPAYMENT</td>
                    <td>
                        <input id="MPPM" type="number" name="MP" />
                        <select id="Sel">
                            <option value="0">Per week</option>
                            <option value="1">Per fortnight</option>
                            <option value="2">Per Month</option>
                        </select><br/><br/>
            <div>  
              
                <input id="next" type="submit" value="Income Expenses &raquo;"/>
                
               
            </div>
           
        </form>

Please I have provided only a part of code because my page is so big.

  • If you could share a bit of your code then we might can help you with some thing – KhawajaAtteeq Aug 23 '15 at 07:38
  • Or you can find many examples to use cookies to store data and manage state. – KhawajaAtteeq Aug 23 '15 at 07:39
  • I hope this [LINK](http://stackoverflow.com/questions/8183790/asp-net-mvc-keeping-last-page-state) Will help you understand – KhawajaAtteeq Aug 23 '15 at 07:41
  • when you add press back add data to first page and submit , why data lost from second page? Does the tables for first page and second page are referenced to one another ? – Dragon Aug 23 '15 at 07:43
  • Sadaquat, when I add data and press submit button from first page, then all text box value will disappear and I have to re-enter it again and I cannot afford to do that as i have around 50 text box which take input in the second page – Prakash Kandel Aug 23 '15 at 08:26

2 Answers2

0

The only way to do this is to transfer the changes real time to the server, in the keypress/ change events. You could use an ajax call for this. After the user navigates to this second page for the second time, you can fill the values he enters earlier

Luc
  • 1,491
  • 1
  • 12
  • 21
  • Can you please give me a very short scenario. Though my page contains many input fields but you can explain me by providing only one input in both pages. Thank you very much – Prakash Kandel Aug 23 '15 at 07:36
0

Firstly If you are dealing with ASP.NET MVC, I would strongly recommend you to use HTML Helpers to create your view like HTML.TextBox() or HTML.Label() etc, and bind these elements with your model so that at every request the values will be updated as per the type of Request GET / POST.

Secondly Pressing browser's back/forward button shows you the last cached page, due to which the values may be obsolete, I suggest you to have your own next previous button and initiate get request for the same.

In case you are troubled by the browser's button, you can check the page referrer accordingly and have that check at every post request

Tushar Gupta
  • 15,504
  • 1
  • 29
  • 47