Search Persits Software Knowledge Base

 

Article PS01043048

When hitting Refresh button, another record is added to the table

Problem Description

After adding a new record with AspGrid, if a user hits the Refresh button on the browser, another identical record is added to the table.

Solution

To prevent an unwanted record from being added to the table when the Refresh button is hit, a session variable may be used to store the last query string content. If the current query string value is the same as the previous value, it means that the Refresh button was hit, and no updates should be performed.

The following code snippet demonstrates the technique:

<%
...
' concatenate together names and values from Query String
For Each Item in Request.QueryString
   Set SubItem = Request.QueryString(Item)
   NewString = NewString & Item
   For i = 1 To SubItem.Count
      NewString = NewString & SubItem(i)
   Next
Next

' Compare new query string with previos one
If NewString = Session("TheQueryString") Then
    Grid.IgnoreCommands
' Do not update
End If

' Save new query string
Session("TheQueryString") = NewString

Grid.Display
%>

If your grid uses the POST method (the property MethodGet is set to False) the code above must use Reqest.Form instead of Request.QueryString, as follows:

<%
...
Grid.MethodGet = False
...
For Each Item in Request.Form
   Set SubItem = Request.Form(Item)
   ...
Next

...
%>

Created: 2/8/2002 5:06:59 AM
Last Modified: 2/9/2002 4:18:59 PM

Copyright © Persits Software, Inc. 1998 - 2018
For technical support, write to support@persits.com.