Skip to content

<AjaxButton>

The AjaxButton tag renders a push-button that, when clicked, makes a jQuery AJAX call to a URL and inserts the returned HTML into a target element on the page — all without a full page postback. Use it to build dynamic UIs (load details, swap panels, refresh sections) without writing JavaScript.

Requires jQuery

This control depends on jQuery being included in the page. DNN typically includes jQuery automatically; if your install doesn't, use <ScriptBlock> to add it.

Url is required

You must specify Url. You must also specify either Target (where to put the response) or OnSuccess (your own callback to handle it).

Example

html
<AddForm>
  <SubmitCommand CommandText="UPDATE EmployeeReview SET Rating=@Rating" />

  <Label>Submit Rating for Employee</Label>
  <DropDownList Id="Rating" DataField="Rating" DataType="Int32">
    <ListItem Value="1">Poor</ListItem>
    <ListItem Value="2">Sub-Par</ListItem>
    <ListItem Value="3">Average</ListItem>
    <ListItem Value="4">Above Average</ListItem>
    <ListItem Value="5">Excellent</ListItem>
  </DropDownList>
  <AjaxButton Text="View Employee History" Url="mysite.com/history.aspx?eid=100"
              Target="#divHistory" />
  <div id="divHistory"></div>
  <AddButton Text="Add Rating" /> <CancelButton Text="Nevermind" />
</AddForm>

Properties

PropertyValuesDefaultDescription
Url *URLThe URL the AJAX request is sent to
TargetjQuery selectorThe element(s) whose HTML will be replaced with the response. Required unless OnSuccess is specified
TextstringCaption displayed on the button
CssClassstringCSS class name(s) for styling the control
DataTypestringjQuery dataType for the AJAX call (e.g. json, html, text)
EnabledTrue FalseTrueWhen False, the control is disabled (grayed out and not interactive)
HeightsizeHeight of the control
IDstringUnique identifier for the control within the form
LoadingCssClassCSS classCSS class applied to the loading image while the AJAX call is in flight
LoadingImageUrlURLImage displayed next to the button while the AJAX call is in flight
Methodget postgetHTTP method used for the AJAX request
OnErrorJS function nameJavaScript function called if the AJAX request fails
OnSuccessJS function nameJavaScript function called with the response. When set, the response is not automatically inserted into Target
StylestringInline CSS (e.g. color: red; border: solid 1px black;)
ToolTipstringText displayed on mouse hover
VisibleTrue FalseTrueShows or hides the control
WidthsizeWidth of the control

* Required property

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

  • Url: The URL the AJAX request is sent to. The tilde (~) represents the application root. Required.

  • Target: A jQuery selector identifying the element(s) whose HTML will be replaced with the response. Use #elementId to target a single element by ID (e.g. #divResults), or .className to target all elements with a CSS class (e.g. div.results). Required unless you provide an OnSuccess callback that handles the response yourself.

  • LoadingImageUrl: A URL to an image (typically an animated spinner) shown immediately to the right of the button while the AJAX request is in flight. The image is removed automatically when the call completes successfully. The tilde (~) represents the application root. If omitted, no loading indicator is shown.

  • LoadingCssClass: CSS class applied to the loading image. Useful for positioning or styling the spinner. Ignored if LoadingImageUrl is not specified.

  • OnSuccess: The name of a JavaScript function to call when the AJAX call completes successfully. If specified, the function is called with the response data and the default behavior (inserting the response into Target) is skipped — your function is responsible for doing whatever needs to happen.

    js
    function doSomethingCool(data) {
      alert("The following data was returned: " + data);
    }

    Then on the control: OnSuccess="doSomethingCool" (function name only — no parens).

  • OnError: The name of a JavaScript function to call if the AJAX call fails. The function receives the standard jQuery jqXHR, textStatus, and errorThrown arguments.

    js
    function myErrHandler(jqXHR, textStatus, errorThrown) {
      alert("The following error occurred: " + textStatus);
    }

    Then on the control: OnError="myErrHandler" (function name only — no parens).