Persits Software, Inc. Knowledge Base Articles

HOWTO: Preserving external parameters

Problem Description

When a parameter is passed to AspGrid from another page or frame, the parameter value is not preserved once a user reloads the page by clicking on an Edit, Add New, Sort or any other AspGrid button.

For example, your grid may be based on a SELECT statement with a WHERE clause using an external parameter id, as follows:

Grid.SQL = "select id, name, phone from employees where dept_id = " & Request("id")

Clicking on an edit button once the grid is displayed will cause a run-time error because Request("id") now evaluates to an empty string.


To preserve your parameter you must include a corresponding hidden variable in every form AspGrid internally generates. To do so, use the top-level property ExtraFormItems , for example:

Grid.ExtraFormItems = "<INPUT TYPE=HIDDEN NAME=id VALUE=" & Request("id") & ">"

It is recommended that you use the generic Request collection instead of Request.Form or Request.QueryString.