Post-redirect-receive (PRG) summary page on submit

So I read this method called PRG as a way of addressing the double form submission issue. However, I have yet to find an idea of ​​how the Summary Page / Success Message page is displayed to the user. The only way I can think of is to store the session variable, but I don't want it to persist across multiple updates. It should show the message / summary once and execute. Also, it would be ideal if the user was unable to return to a previously submitted page.

Here is my PRG code:

Protected Sub InsertRequest() Handles wizard.FinishButtonClick
    Using connection As New SqlConnection(connectionStr)
        Dim insertQuery As New SqlCommand("spInsertRequest", connection)
        insertQuery.CommandType = CommandType.StoredProcedure

        '1 - SETUP SQL PARAMETERS (omitted for brevity)

        '2 - POST (inserts record into DB)
        Try
            connection.Open()
            insertQuery.ExecuteNonQuery()
            connection.Close()
        Catch ex As Exception
            Logger.WriteToErrorLog(Me, ex.Source, ex.Message, ex.StackTrace)
        End Try

    '3 - REDIRECT (to the same page and...)
    Try
        Dim urlRedirect As String = If(IsNothing(Request.Url), "", IO.Path.GetFileName(Request.Url.AbsolutePath)) 'Gets the filename of the current page.
        If Not String.IsNullOrEmpty(urlRedirect) Then
            Session.Add("referrerPage", urlRedirect) 'Used for identifying when the page is being redirected back to itself.
            PageExt.AddParam(urlRedirect, "id", recID.ToString)
            Response.Redirect(urlRedirect)
        End If
    Catch ex As Exception
        Logger.WriteToErrorLog(Me, ex.Source, ex.Message, ex.StackTrace)
    End Try
End Sub

'4 - GET (Display 'Success' message/summary here)

      

The question is how to display this redirect message that is received directly from submit, and preferably not for any additional updates? Or just simply display a message regardless of updates, whichever is simpler and makes the most sense. Thank;)

+3


source to share


1 answer


The trick with messages that only appear once is to use the concept of "flash" session data.

This usually works to store the "message" (or whatever other "success" data you need) in the session prior to redirection. Then, when processing the redirect, be sure to remove the flash data from the session before sending a "successful page" response.



This way, if the user tries to return to the success page, the flash data will not be displayed in the session, so you will not display it twice. To be nice to the users, you can check for no flash data and display a nice error message if they try to navigate to the success page outside of the Post-Redirect-Get stream.

This is exactly what the Grails framework (in the Groovy world) does, and it works very well.

+2


source







All Articles