Skip to content

<CancelButton>

The CancelButton tag renders as a push-button at run-time. When clicked, the form closes without performing any server-side processing — no SubmitCommand runs, no validators fire. Use <CancelImage> for a clickable image button or <CancelLink> for a hyperlink that performs the same action.

Validation is skipped

CancelButton sets CausesValidation="False" automatically, so any <Validate> controls on the form will not block the cancel action. This is what makes it usable as a true "back out" button.

CancelButton works in both <AddForm> and <EditForm>.

Example

html
<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"><AddButton Text="Add"/> <CancelButton Text="Cancel"/></td>
     </tr>
   </table>
</AddForm>

Properties

PropertyValuesDefaultDescription
TextstringCaption displayed on the button
AccessKeystringKeyboard shortcut character (e.g. F for Alt+F)
CssClassstringCSS class name(s) for styling the control
EnabledTrue FalseTrueWhen False, the control is disabled (grayed out and not interactive)
HeightsizeHeight of the control
IDstringUnique identifier for the control within the form
OnClientClickJavaScriptClient-side script to run when the button is clicked
RedirectURL | .URL the user is redirected to after the cancel action
RedirectMethodGet PostGetHTTP method used for the redirect
StylestringInline CSS (e.g. color: red; border: solid 1px black;)
TabIndexintegerTab order for keyboard navigation
ToolTipstringText displayed on mouse hover
VisibleTrue FalseTrueShows or hides the control
WidthsizeWidth of the control
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.

PropertyValuesDescription
BackColorcolor name | #ddddddBackground color of the control
BorderColorcolor name | #ddddddBorder color of the control
BorderStyleNotSet None Dotted Dashed Solid Double Groove Ridge Inset OutsetBorder style of the control
BorderWidthsizeBorder width of the control
Font-BoldTrue FalseBold text
Font-ItalicTrue FalseItalic text
Font-NamesstringFont family name
Font-OverlineTrue FalseOverline text decoration
Font-SizeXX-Small X-Small Small Medium Large X-Large XX-Large or sizeFont size
Font-StrikeoutTrue FalseStrikethrough text decoration
Font-UnderlineTrue FalseUnderline text decoration
ForeColorcolor name | #ddddddText color of the control

Property Details

  • OnClientClick: A JavaScript expression to run when the button is clicked, before the server-side processing happens. Useful for confirmation dialogs (e.g. return confirm('Discard changes?');). If your script returns false, the button does nothing further. If it returns true (or doesn't return anything), the button proceeds normally.

  • 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. Post submits 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's ID, not its DataField.