locked
cleaning up what happens if user hits BACK after redirect RRS feed

  • Question

  • User379720387 posted

    I have a form that let's users enter information. If the user has no posting privileges, a dialog comes up and there I explain why they cannot post, and there is a redirect to the page where they can buy. It is kind of rough because it briefly displays the form, and then shows the buy page

    Unfortunately when you hit back, after the redirect, it then displays the form.

    Here is the dialog code:

    $("#dialog-message1").dialog({
                modal: true,
                buttons: {
                    Ok: function () {
                        $(this).dialog("close");
                        window.location.href = "/Buy.cshtml"
                    }
                }
            });

    As an improvement I wrapped the entire form in an if statement

    @if (balancestatus != "no go")
    {
    my form here}
    Response.Redirect("~/Buy.cshtml/");

    Now when you select BACK after the redirect has completed is displays:

    Response.Redirect("~/Buy.cshtml/")


    What is the proper way to clean this up?

    TIA

    Robert

    Monday, July 22, 2013 11:45 AM

Answers

  • User38443587 posted

    Hello, About your question I’ll give you my suggestion.

    1. Is it possible to delete the last entry from the list of pages the browser keeps?

    If you want to clean up the values whenever the page loads, just clean in event “onload”. We can also do this depends on some check such as is there any parameters in url.  Below is a demo:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        
    </head>
    <body>
        <form id="form1" >
        <script src="Scripts/jquery-1.7.1.js"></script>
            <script type="text/javascript">
                $(document).ready(function () {
                    if (window.location.href.split('?').length == 1)   // do some check 
                    {
                        $("#names").val("");   //clean up values
                    }
    
                });
                function test()   
                {
                    location.href = "Default.aspx";   
                }
    </script>
        <div>
           name: <input type="text" value="" name="1" id="names" />
        </div>
        </form>
         <input type="button" name="ss" value="d3d" id="Button1" onclick="test();" />
    </body>
    </html>
    

    From this demo we can view this page by “http://..../WebForm1.aspx” or “http://..../WebForm1.aspx?xx=0”. Then we can find the difference.

     

    1. How does one delete page A from the history?

    About this question I don’t suggest you to do this. Because you want to delete the client file by your code, it is always not allowed.

    Thank you!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 24, 2013 10:03 PM

All replies

  • User38443587 posted

    Hello,

    Thanks for posting.

    From your description, you want to clear up the values when hit back. I think you can clean the values in function “load()”.

    Here is parts of code:

    <body onload="loads()">
    
        <form id="form1" >
    
        <script src="Scripts/jquery-1.7.1.js"></script>
    
            <script type="text/javascript">
    
                function loads()
    
                {
    
                    $("#names").val("");
    
                }
    
     
    
    name: <input type="text" name="1" id="names" />
    

     

    please try it, hope it can help you. Thank you.

    Tuesday, July 23, 2013 4:21 AM
  • User379720387 posted

    I have absolutely no idea what this is supposed to do, let alone where to implement it in my code.

    Tuesday, July 23, 2013 8:54 AM
  • User38443587 posted

    Hello, I apologize to you for my inadequate description. From your description, You mean that you do something in page A then redirect to page B, after that you hit BACK then page A displays with values you put last time. Your question is how to clean up this values. If I am right, you can use my code in your page A. when you hit BACK and page A displays your browser will not send request to the server, it just get info from Browser Caching, so the info you put last time is also there, however the onload event works every time, so you could clean up info in this event. If I am wrong, would you please give me more detail info and I will follow this issue in the future.

    Tuesday, July 23, 2013 11:14 PM
  • User379720387 posted
    page A contains code to collect data and display a form as well as some code to determine if the form should be displayed. if the form is not displayed the user sees a dialog (jQuery) which says you are not allowed to enter this form. after the user clicks ok, the form shows and then the redirect goes to page B. I would prefer that the form is not shown at all, but I can live with that for now. from Page B when the user hits back, it now shows the form. how can I prevent the form from showing briefly and how can I prevent that no matter what that form gets shown on back?
    Tuesday, July 23, 2013 11:36 PM
  • User895691971 posted

    Hi, what happens when you use 

    <input type="text" name="itsname" value="" />

    So everytime the page loads, it gets the value "". Does this work for you?

    Wednesday, July 24, 2013 2:44 AM
  • User38443587 posted

    Thanks for your sharing, Now I see what you want. I reappeared the situation you post local. Below is my code:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        
    </head>
    <body>
        <form id="form1" >
        <script src="Scripts/jquery-1.7.1.js"></script>
            <script type="text/javascript">
                
                function test()   // for this function you can find that the textbox showing briefly then redirect to page "Default.aspx"
                {
                    location.href = "Default.aspx";   // this will work at the end of this function
                    $("#names").show();
                }
    </script>
        <div>
           name: <input type="text" value="" name="1" id="names" style="display:none;" />
        </div>
        </form>
         <input type="button" name="ss" value="d3d" id="Button1" onclick="test();" />
    </body>
    </html>

    Because I don’t have your javascript code, If you still have any questions, it is wonderful that post your javascript code and I can give insufficient help.  Thank you.

    Wednesday, July 24, 2013 3:11 AM
  • User379720387 posted

    I have been able to resolve my problem by wrapping the form in an extra if-statement.

    If the condition is met the form does not get displayed, but the redirect still takes place.

    When the user clicks BACK, after the redirect, it displays a page with links to the various other pages, but not the form.

    Not as clean as I would have liked but, much better than what I had before.

    Is is possible to delete the last entry from the list of pages the browser keeps?

    For instance suppose the browser history is:

    page F

    page E

    page A (my page from the code below)

    page B (the redirect page).

    How does one delete page A from the history, so that when BACK is selected the browser takes the user to page E?

    Here is the concept of my code so far:

    @{
    // code here to collect data for form purpose
    // code here to determine status go or nogo
    if(IsPost) 
       {
        code here to read form data and store in db
       }
    }
    
    @if (status == "no go") //this displays the dialog with the warning
    {
    <div id="dialog-message1" title="Warning: account balances">
    <p><span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>@modal</p>
    <br/>
    <p> No Balance:</p>
    <br/>
    </div>
    }
    
    @if (balancestatus != "no go")
    {
    <form method="post">
    // the rest of the form here
    </form>
    }
    
    <script> // jQuery for the dialog
    $("#dialog-message1").dialog({
            modal: true,
            buttons: {
                Ok: function () {
                    $(this).dialog("close");
                    window.location.href="/Buy.cshtml"
                }
            }
        });
    </script>



    Wednesday, July 24, 2013 5:14 AM
  • User38443587 posted

    Hello, About your question I’ll give you my suggestion.

    1. Is it possible to delete the last entry from the list of pages the browser keeps?

    If you want to clean up the values whenever the page loads, just clean in event “onload”. We can also do this depends on some check such as is there any parameters in url.  Below is a demo:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        
    </head>
    <body>
        <form id="form1" >
        <script src="Scripts/jquery-1.7.1.js"></script>
            <script type="text/javascript">
                $(document).ready(function () {
                    if (window.location.href.split('?').length == 1)   // do some check 
                    {
                        $("#names").val("");   //clean up values
                    }
    
                });
                function test()   
                {
                    location.href = "Default.aspx";   
                }
    </script>
        <div>
           name: <input type="text" value="" name="1" id="names" />
        </div>
        </form>
         <input type="button" name="ss" value="d3d" id="Button1" onclick="test();" />
    </body>
    </html>
    

    From this demo we can view this page by “http://..../WebForm1.aspx” or “http://..../WebForm1.aspx?xx=0”. Then we can find the difference.

     

    1. How does one delete page A from the history?

    About this question I don’t suggest you to do this. Because you want to delete the client file by your code, it is always not allowed.

    Thank you!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 24, 2013 10:03 PM