Passing Primary and Foreign Key Values in URLs

Parameters such as primary and foreign key values can be passed from one page to another through the destination page’s URL.  Specify the URL and URL parameters via the Button Action Wizard in the Property Sheet for any button such as PushButton, LinkButton, and ImageButton; and for links such as Hyperlink.

Parameter names are specified in the URL field in the Button Action Wizard and the URL may contain multiple parameter names; substitution variables for the parameter values are specified in the URL Parameters field.  The URL Parameters field specifies a comma delimited set of arguments that are passed on the URL.

Passing primary key values between pages in URLs

Passing primary key values from one page to another via URLs is very straightforward.  In the Property Sheet, select the “Button actions” property and in the Button Action Wizard, specify:

Group

Property

Setting

[Application Generation]

Button actions

Redirect

Button Action Wizard

URL

ShowEmployeePhoto.aspx?Employees={PK}

Button Action Wizard

URL Parameters

Employees={PK}

This passes the primary key value to the destination page via the URL.  Even though the argument is called “PK”, what is passed to the URL is an XML element that specifies the full primary key of the record.  If the primary key is composite key, the composite key is passed as an argument.

If the ID of the field is a single integer value, you can use the “FV” URL Parameter type to pass the value to the URL.  However, if you later change the Id to a more complex key, your existing pages will not work correctly.  As such, we recommend always using the “PK” URL Parameter type to pass primary keys to other pages via an XML encoded composite key structure.

Passing foreign key values between pages in URLs

In the following example, the URL uses a parameter to pass a foreign key within the Employees record.  The URL parameter field is specified as FK:FK_Employees_Employees.  This means that the parameter will be substituted with the foreign key (FK) value as specified by FK_Employees_Employees.  The FK_Employees_Employees name indicates a foreign key link between the employee table and another record in the Employees table (the manager of the employee).

Group

Property

Setting

Appearance

Text

Add

[Application Generation]

Button actions

Redirect

Button Action Wizard

URL

./EmployeeFKLink.aspx?Employee={FK:FK_Employees_Employees}

Button Action Wizard

URL Parameters

FK:FK_Employees_Employees

Passing virtual primary keys in URLs

If you are using a database view or custom query (defined in Iron Speed Designer) as the source of data, make sure that the database view or custom query has a Virtual Primary Key (VPK) defined.

If a virtual primary key is not defined, then your application will not be able to access the ID or the record or any field within the record since there is no “handle” available to read the record from the database.  As such, passing a parameter such as ID or FV:EmployeeName will not result in the value being substituted for the parameters.

Passing composite key values in URLs

Most database tables have a single primary key such as an Id field.  But, some tables may have a composite primary key such as a Customer table with First Name and Last Name as a composite key.  In this case, you must pass the composite key in the URL as an XML structure containing both elements of the composite key, e.g., the first name field as “Fred” and last name field as “Jones”.  This is why Iron Speed Designer passes keys in an XML structure as the default.

The composite key XML structure is:

<key>

     <cv>

          <c>EmployeeID</c>

          <v>1</v>

     </cv>

</key>

“cv” is the column value.  For composite keys, your <key> structure will have several <cv> entries, one for each field in the composite key.

“c” is the column (field) name.

“v” is the column value, typically a numeric ID value or a text string.

If you are not using composite keys, you can change this very easily to a single field primary key by passing FV:Id instead of ID (PK).  The difference is that you are passing the field value of the "Id" field instead of the ID of the record.  Make sure you spell the case of the field properly (e.g., Id, id, ID, iD or whatever) in the URL Parameters on the Button Action Wizard (accessed via the “Button actions” property in the Property Sheet) for the button or other control.

See Also

Using URL Parameters

URL Query String Format

Passing Field Values in URLs

Example: Passing a Record ID from an Add Record Page