Click here to Skip to main content
15,881,729 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Happy Friday Experts!

I have a website, where there is a submit button which has code as below

C#
If Page.IsValid Then
               Dim dsCustInfo As DataSet = New DataSet()
               Dim dsDealerInfo As DataSet = New DataSet()
               Dim dsAsDealerInfo As DataSet = New DataSet()
               Dim dsVehicleInfo As DataSet = New DataSet()
               Dim dsOtherDetails As DataSet = New DataSet()
               InsertData()
               SendEmail()
               ScriptManager.RegisterStartupScript(Page, Page.GetType(), "scr", "closeLoading();", True)
               ClearAll()
               Session.Abandon()
               ViewState.Clear()
               Page.Response.Cache.SetCacheability(HttpCacheability.NoCache)
               '  ClientScript.RegisterStartupScript(Me.GetType(), "myalert", "Your information has been submitted successfully", True)
               Dim message As String = "alert('Your information has been submitted successfully.')"
               ScriptManager.RegisterClientScriptBlock(TryCast(sender, Control), Me.GetType(), "alert", message, True)
           Else
               Dim ms As String = "alert('Please enter required fields.')"
               ScriptManager.RegisterClientScriptBlock(TryCast(sender, Control), Me.GetType(), "alert", ms, True)
           End If



And on the client click of same button, I have following javascript code...

function Valid() {
        debugger;
        var totalRows = $("#<%=gdvLineItems.ClientID %> tr").length;
        if (totalRows != 0) {
            if (Page_ClientValidate("Required") == true) {
                //StartProgressBar()
                PrintPanel();
                blockUI();
                return true;

            }
            else {
                validateAndHighlight();
                alert("Please fill the Required fields");
                return false;
            }
        }
        else {
            alert("Please Add Line Items/ Tires");
            return false;
        }
    }


Now, all the validations are working perfectly.
After I submit, I get a message from code behind "Success message" and now I moved to a different page2.aspx. It is loaded without any problem. I decided to click on back button of browser and I see that success message instead of showing me entirely the page. It shows the Alert message (success message) .

Could someone help me with this?
I believe I have something to do with caching and postbacks but not sure how or what to do
Posted
Updated 15-Dec-15 9:27am
v3
Comments
jgakenhe 11-Dec-15 14:16pm    
I don't know if I can help, but this is what I am thinking and it might help you. Since you are clicking the back button, you're getting a cache version of the previous page; thus it is submitting your code again. To fix that I'd try and expire the submission page; so it doesn't create a cache and it doesn't submit again when you click the back button.

There are several ways to do it. such as:
'code behind - convert to vb.net
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(Now.AddSeconds(-1));
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");
or
'code behind - convert to vb.net
Response.Expires = -1;
Response.Cache.SetNoServerCaching();
Response.Cache.SetAllowResponseInBrowserHistory(false);
Response.CacheControl ="no-cache";
Response.Cache.SetNoStore();
or
<!-- put in html, between beg/close header tags -->
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="0">

Let me know if this works for you.
sudevsu 11-Dec-15 16:01pm    
I tried the first one already and I got this message in the browser
"This document is no longer available.

The requested document is not available in Firefox's cache.

As a security precaution, Firefox does not automatically re-request sensitive documents.
Click Try Again to re-request the document from the website."

1 solution

Try adding below to Page Load.
C#
protected void Page_Load(object sender, EventArgs e)
{
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
}
 
Share this answer
 
Comments
sudevsu 15-Dec-15 8:54am    
What happens if this is added Tadit. I can still click on back button on the browser and it should "requested document is not available on Firefox cache"
sudevsu 15-Dec-15 12:14pm    
Yes. I have web page which is like information gathering form and on clicking submit, it shows a success message after inserting the data. Now I clicked on Page2.aspx. Now back button on the browser is clicked and I see the success message instead of loading the entire page. This one is being a problem since last 2 weeks. I couldn't solve. just losing hopes
sudevsu 15-Dec-15 12:18pm    
BTW, this can be only positive to IE. Not FF, Chrome.
sudevsu 15-Dec-15 15:26pm    
Also I have tried and I get "the requested document is not available in Firefox's cache." I dont' want this message. Instead I want the entire page to reload again. I believe there is no answer for this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900