<CancelImage>
The CancelImage tag renders as a clickable image at run-time. When clicked, the form closes without performing any server-side processing — same behavior as <CancelButton>, just rendered as an image.
Validation is skipped
CancelImage sets CausesValidation="False" automatically, so any <Validate> controls on the form will not block the cancel action.
CancelImage works in both <AddForm> and <EditForm>.
Example
<AddForm>
...
<table>
<tr>
<td>
<Label For="txtFirstName" Text="First Name" />
<TextBox Id="txtFirstName" DataField="FirstName" DataType="string" />
</td>
</tr>
<tr>
<td>
<Label For="txtLastName" Text="Last Name" />
<TextBox Id="txtLastName" DataField="LastName" DataType="string" />
</td>
</tr>
<tr>
<td colspan="2">
<AddImage AlternateText="Add" ImageUrl="~/images/add.gif" />
<CancelImage AlternateText="Cancel" ImageUrl="~/images/cancel.gif" />
</td>
</tr>
</table>
</AddForm>Properties
| Property | Values | Default | Description |
|---|---|---|---|
| ImageUrl | URL | Path to the image file to display | |
| AccessKey | string | Keyboard shortcut character (e.g. F for Alt+F) | |
| AlternateText | string | Alt text for accessibility (screen readers) and search engines | |
| CssClass | string | CSS class name(s) for styling the control | |
| Enabled | True False | True | When False, the control is disabled (grayed out and not interactive) |
| Height | size | Height of the image | |
| ID | string | Unique identifier for the control within the form | |
| ImageAlign | NotSet Left Right Baseline Top Middle Bottom AbsBottom AbsMiddle TextTop | NotSet | Alignment of the image with respect to surrounding content |
| OnClientClick | JavaScript | Client-side script to run when the image is clicked | |
| Redirect | URL | . | URL the user is redirected to after the cancel action | |
| RedirectMethod | Get Post | Get | HTTP method used for the redirect |
| Style | string | Inline CSS (e.g. color: red; border: solid 1px black;) | |
| TabIndex | integer | Tab order for keyboard navigation | |
| ToolTip | string | Text displayed on mouse hover | |
| Visible | True False | True | Shows or hides the control |
| Width | size | Width of the image |
Deprecated Properties
These properties use ASP.NET inline styling and are no longer recommended for modern web development. Use the CssClass property to apply CSS classes or the Style property for inline CSS instead.
| Property | Values | Description |
|---|---|---|
| BackColor | color name | #dddddd | Background color of the control |
| BorderColor | color name | #dddddd | Border color of the control |
| BorderStyle | NotSet None Dotted Dashed Solid Double Groove Ridge Inset Outset | Border style of the control |
| BorderWidth | size | Border width of the control |
| Font-Bold | True False | Bold text |
| Font-Italic | True False | Italic text |
| Font-Names | string | Font family name |
| Font-Overline | True False | Overline text decoration |
| Font-Size | XX-Small X-Small Small Medium Large X-Large XX-Large or size | Font size |
| Font-Strikeout | True False | Strikethrough text decoration |
| Font-Underline | True False | Underline text decoration |
| ForeColor | color name | #dddddd | Text color of the control |
Property Details
ImageUrl: Path to the image file. The tilde (
~) represents the application root, soImageUrl="~/images/cancel.gif"resolves to/dnntestsite/images/cancel.gifon a development install and/images/cancel.gifon production.OnClientClick: A JavaScript expression to run when the image is clicked, before the server-side processing happens. Useful for confirmation dialogs (e.g.
return confirm('Discard changes?');). If your script returnsfalse, the button does nothing further.Redirect: After the cancel action, redirect the user to this URL. Field tokens may be used in the value (and are URL-encoded automatically), but function tokens like
[[Portal:ID]]and[[User:ID]]are not supported here. Use a single period (.) as a shortcut for "the current page".RedirectMethod: The HTTP method used for the redirect.
Get(the default) appends form values as query string parameters.Postsubmits them as a form POST.Post uses ID, not DataField
When
RedirectMethod="Post", the field names in the posted form come from each form control'sID, not itsDataField.