Parameters such as primary and foreign key values can be passed from one page to another through the destination page’s URL. Parameters and their values are passed as part of the URL and URL Parameters fields in the Page Properties dialog that are available for any of the buttons such as PushButton, LinkButton, and ImageButton; and for links such as Hyperlink.
Parameter names are specified in the URL field 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 in the Page Properties dialog specifies a comma delimited set of arguments that are passed on the URL and uses {0}, {1}, etc. to pick the first argument, second argument, etc. Note that the first argument is {0} since the arguments numbers are zero based.
Passing primary key values from one page to another via URL’s is very straightforward. In the tag’s Properties dialog, specify:
|
Tag Property |
Setting |
|
Button Command |
Redirect |
|
URL |
{0} |
|
URL Parameters |
ID |
This passes the primary key value to the destination page via the URL. Even though the argument is called “ID”, 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 “ID” or “PK” URL Parameter types to pass primary keys to other pages via an XML encoded composite key structure.
In the following example, the URL uses an argument {0} to indicate the substation of the first argument. The argument itself is specified in the URL Parameters field as FK:FK_Employees_Employees. This means that the parameter {0} 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).
|
Tag Property |
Setting |
|
Button Text |
Add |
|
Button Command |
Redirect |
|
URL |
./EmployeeFKLink.aspx?Employee={0} |
|
URL Parameters |
FK:FK_Employees_Employees |
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 and you will see the URL still contain {0}, {1}, etc.
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 differernce 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 Bindings tab of the Page Properties dialog for the button or other control.