Reputation: 1310
I've an Asp.net .aspx page. I am taking a simple contact us page for example. The page has 3 fields- name/email/question. The scenario is, A user entered a wrong email address, in response, system shows an error message by checking it to a Regex.
Now if user hits back browser button or backspace key, browser displays the same page without error message- that means 1 step behind.
If user does 2 concurrent mistakes- 1)Leaves name box empty, hits Submit (error message displays says all fields are mandatory). 2)Wrong email, hits Submit (error message displays wrong email entered)
Now if user hits back browser button or backspace key, browser displays the same page with previous error message (for empty box) i.e 1 step behind. Again hits back, displays same page without any error message, i.e 2 steps behind.
I do not want the back button or backspace to do these unwanted actions. I also do not want to disable back button or not to cache anything.
What I need, when user hits back button or backspace, they should be landed to the previously browsed different page, not the same page. That means, I do not want browser cache to hold page during multiple postbacks. Rather, cache should hold page only once when it landed initially.
I heard sometime that this approach called smartnavigation, I tried googling but couldn't find something very useful and optimized. This was the best article I found yet (not sure this is what I am looking for). http://support.microsoft.com/kb/913721
The problem is, I am not fully sure How to exactly reference this issue.
I hope my question is pretty straight forward (I tried to be clear). Please let me know if something is not clear.
I would greatly appreciate any kind help.
Thanks in advance.
Upvotes: 0
Views: 1429
Reputation: 21
Here is another solution. Try to add <% Response.CacheControl = "no-cache";%> above the "head" tag
Upvotes: 0
Reputation: 1879
I believe you could just put your controls inside an UpdatePanel with UpdateMode set to Always i.e.
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
<ContentTemplate>
// Your controls
</ContentTemplate>
</asp:UpdatePanel>
You will also need a ScriptManager inside the Form element of the Page e.g.
<form id="form1" runat="server">
<asp:ScriptManager runat="server" EnablePartialRendering="true" />
....
</form>
This will stop the Page doing a full postback and should stop the behaviour you have described. I would also use client side validation with a RegularExpressionValidator or RequiredFieldValidator etc.
Upvotes: 2