Persits Software, Inc. Knowledge Base Articles

When a data-bound form with FormOnSubmit is used, Cancel button does not work

Problem Description

When a data-bound form is used with client-side JavaScript validation enabled (the property Grid.FormOnSubmit is used to set a validation routine), the Cancel button does not appear to work correctly.

When a new record is being added and a blank data-bound form appears, clicking on the Cancel button does not return the browser back to the record list. Instead, the page refreshes and the first record in the recordset is displayed in the data-bound form.

This behavior can be replicated by adding the line

<%
...
Grid.FormOnSubmit = "return Validate();"
...
%>

and the corresponding client-side script routine

<SCRIPT LANGUAGE="JavaScript">
function Validate()
{
   return true;
}
</SCRIPT>

to the sample file form.asp used in Chapter 10 of the AspGrid manual.

Solution

Add the following line to the file form.asp right after all other Response.Redirect calls:

If Request("id") = "" and Request("AspGridAdd1") = "" and Request("AspGridCancel1") = "" and Request("AspGridSave1") = "" and Request("AspGridDelete1") = "" Then Response.Redirect "list.asp"

You may need to replace the field name "id" with your own field name, if necessary.