I have a MVC application with a form that is dynamicly populated with jquery, when submitting and then hitting back on the browser the dynamic controls will not be visible anymore. I have come up with a coule of possible solutions :
Place a script on the registrationform that contacts the service onPageLoad and check if the user have hit the back button, if so, then reload the page and get new html with correct dynamic content from service. Im however not sure how to check if the back
button have been used.
When hitting submit on registrationform, let the service redirect to the same page again but with the correct dynamic content. On PageLoad redirect the user to the next page(Preview). This should mean that when hitting back one time the page will load with
the correct dynamic content.
Explain to enduser to not use the back button, this is according to me a bad solution.
I have found that this webpage :
http://www2.blocket.se/ai/form/0 handle the problem nicly, the question is how? It looks like it is populating the dynamic content with jacascript on pageLoad? But this seemse to be ALOT of work.
You may want to clear the content in the control when you click the Back Button. You can force the cache to expire for it. You can refer to the below code. You can put the code in the Application_BeginRequest() mthod of Global.asax.cs file. When you request
to the server it will fire.
I thought that there is no service call when clicking the back button in a browser? I thought that the prev page is shown from cache and the layout is based on how the page looked like when it arrived at the client and not how it looked like when submitted.
You can try the Qi Wu code. If you have some problem you can post it out.
And you can see a checbox above the Post button. If you don't want to receive email you can not select it. When the thread update you will receive a email it is because the design of the asp.net forum . It can let you know someone has helped you.
I have now tested your code and it seems to solve the problem. I hade no idee that the browser made a call to the server when using back? My thought was that all data was cached on client before submit and when hitting back this cache was used?
I do only need this on a specific page and I have found that I can use the HttpContext to check the current url of the request. What does this cache reset really do? Will it clear session/view data or anything like that? Can I see if the request is triggered
by a back button event?
Sorry but this is not the answer. There is no standard for how browsers should handle these tags when back button is used. Some browsers might use its own cache even if the tags states that it should get new data.
Its important that this site works on as many browers as possible, even on mobile devices.
The the question remains, how do I handle the back button?
SnowJim
Member
306 Points
293 Posts
Handle backbutton with dynamic content?
Feb 12, 2012 08:14 AM|LINK
Hi,
I have a MVC application with a form that is dynamicly populated with jquery, when submitting and then hitting back on the browser the dynamic controls will not be visible anymore. I have come up with a coule of possible solutions :
I have found that this webpage : http://www2.blocket.se/ai/form/0 handle the problem nicly, the question is how? It looks like it is populating the dynamic content with jacascript on pageLoad? But this seemse to be ALOT of work.
Pleas help
Qi Wu - MSFT
Contributor
5794 Points
677 Posts
Re: Handle backbutton with dynamic content?
Feb 14, 2012 06:02 AM|LINK
Hi,
You may want to clear the content in the control when you click the Back Button. You can force the cache to expire for it. You can refer to the below code. You can put the code in the Application_BeginRequest() mthod of Global.asax.cs file. When you request to the server it will fire.
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)); HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); HttpContext.Current.Response.Cache.SetValidUntilExpires(false); HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); HttpContext.Current.Response.Cache.SetNoStore();You can find the above methods in the below link.
http://msdn.microsoft.com/en-us/library/system.web.httpcachepolicy.setnostore(v=vs.71).aspx
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
SnowJim
Member
306 Points
293 Posts
Re: Handle backbutton with dynamic content?
Feb 14, 2012 06:22 AM|LINK
Hi,
I thought that there is no service call when clicking the back button in a browser? I thought that the prev page is shown from cache and the layout is based on how the page looked like when it arrived at the client and not how it looked like when submitted.
SnowJim
Member
306 Points
293 Posts
Re: Handle backbutton with dynamic content?
Feb 14, 2012 11:30 AM|LINK
By the way, Why do I get mail when Im the one that updating the thread?
SnowJim
Member
306 Points
293 Posts
Re: Handle backbutton with dynamic content?
Feb 16, 2012 09:17 AM|LINK
Will this work on all browsers?
sanjayjgoswa...
Member
122 Points
31 Posts
Re: Handle backbutton with dynamic content?
Feb 16, 2012 01:38 PM|LINK
Try this script
<div class="container"> <div class="line number1 index0 alt2"><SCRIPTtype="text/javascript"></div> <div class="line number2 index1 alt1">window.history.forward();</div> <div class="line number3 index2 alt2">function noBack() { window.history.forward(); }</div> <div class="line number4 index3 alt1"></SCRIPT></div> <div class="line number5 index4 alt2"></HEAD></div> <div class="line number6 index5 alt1"><BODYonload="noBack();"</div> <div class="line number7 index6 alt2">onpageshow="if (event.persisted) noBack();"onunload=""></div> </div>Richey
Contributor
3816 Points
431 Posts
Re: Handle backbutton with dynamic content?
Feb 18, 2012 01:59 PM|LINK
Hi,
You can try the Qi Wu code. If you have some problem you can post it out.
And you can see a checbox above the Post button. If you don't want to receive email you can not select it. When the thread update you will receive a email it is because the design of the asp.net forum . It can let you know someone has helped you.
SnowJim
Member
306 Points
293 Posts
Re: Handle backbutton with dynamic content?
Feb 26, 2012 06:29 PM|LINK
I have now tested your code and it seems to solve the problem. I hade no idee that the browser made a call to the server when using back? My thought was that all data was cached on client before submit and when hitting back this cache was used?
I do only need this on a specific page and I have found that I can use the HttpContext to check the current url of the request. What does this cache reset really do? Will it clear session/view data or anything like that? Can I see if the request is triggered by a back button event?
BestRegards
SnowJim
Member
306 Points
293 Posts
Re: Handle backbutton with dynamic content?
Feb 27, 2012 07:36 PM|LINK
Sorry but this is not the answer. There is no standard for how browsers should handle these tags when back button is used. Some browsers might use its own cache even if the tags states that it should get new data.
Its important that this site works on as many browers as possible, even on mobile devices.
The the question remains, how do I handle the back button?