Prevent browser from viewing the re-send request dialog box when updating

When the user selects an item from the drop-down list and presses the button, my application displays a list of manually linked data and filtered according to the selected value. If the user clicks the refresh button of the browser, he asks for confirmation if the user is sure that he wants to send the request again.

I do not want the browser to ask about this. How can I avoid this behavior?

As far as I understand, this can be done by implementing the post / redirect / get pattern, but I do not know how to do this in ASP.NET 3.5.

+3
source share
2 answers

, - , , :

// Check to see if the user submitted the form:
if (Page.IsPostBack){
  // Get the Params collection - query and forms
  NameValueCollection params = Request.Params;
  StringBuilder query = new StringBuilder();

  // Iterate over the params collection to build a complete
  // query string - you can skip this and just build it
  // manually if you don't have many elements to worry about
  for(int i = 0; i <= params.Count - 1; i++)
  {
    // If we're not on the first parameter, add an & seperator
    if (i > 0){
      query.Append("&");
    }

    // Start the query string 
    query.AppendFormat("{0}=", params.GetKey(i));

    // Create a string array that contains
    // the values associated with each key,
    // join them together with commas.
    query.Append(String.Join(",", pColl.GetValues(i));
  }

  Response.Redirect(String.Format("{0}?{1}", 
                      Request.Url.AbsolutePath, query.ToString()))
}

, , , .

, .

0

POST, , . .

PRG asp.net, , , ( , ).

, postback asp.net, .

+1

Source: https://habr.com/ru/post/1704751/


All Articles