Sys.CancelEventArgs Class

Provides the base class for events that can be canceled.

Namespace: Sys

Inherits: Sys.EventArgs

var args = new Sys.CancelEventArgs();



Sys.CancelEventArgs Constructor

Initializes a new instance of the CancelEventArgs class.



Sys.CancelEventArgs cancel Property

Gets or sets a value that specifies whether the event source should cancel the operation that caused the event.


This class contains private members that support the client-script infrastructure and are not intended to be used directly from your code. Names of private members begin with an underscore ( _ ).

Event handlers can use the cancel property to cancel the operation in progress. The semantics of canceling an event depend on the event source.

The following example shows how to use the cancel property of the InitializeRequestEventArgs class, which derives from the CancelEventArgs class. In this example, a handler for the initializeRequest event enables an asynchronous postback to be canceled. Script in the handler determines whether an asynchronous postback is currently in progress by using the isInAsyncPostBack property of the PageRequestManager class. If a postback is in progress, the postBackElement property is used to determine the ID of the element that caused the postback. If the ID matches the ID of a button that cancels the postback, the abortPostBack method is called. Otherwise, the current request is canceled by using the cancel property of the CancelEventArgs class.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<script runat="server">

    protected void ButtonClick_Handler(object sender, EventArgs e)

<html xmlns="">
<head id="Head1" runat="server">
    <title>PageRequestManager initializeRequest Example</title>
    <style type="text/css">
    body {
        font-family: Tahoma;
    a  {
        text-decoration: none;
    a:hover {
        text-decoration: underline;
       width: 300px;
       height: 300px;
    div.AlertStyle {
      font-size: smaller;
      background-color: #FFC080;
      height: 20px;
      visibility: hidden;
    div.Container {
      display: inline;
      float: left;
      width: 330px;
      height: 300px;
    <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
            <script type="text/javascript" language="javascript">
                var divElem = 'AlertDiv';
                var messageElem = 'AlertMessage';
                function CheckStatus(sender, args)
                  var prm = Sys.WebForms.PageRequestManager.getInstance();
                  if (prm.get_isInAsyncPostBack() & args.get_postBackElement().id == 'CancelRefresh') {
                  else if (prm.get_isInAsyncPostBack() & args.get_postBackElement().id == 'RefreshButton') {
                     ActivateAlertDiv('visible', 'Still working on previous request.');
                  else if (!prm.get_isInAsyncPostBack() & args.get_postBackElement().id == 'RefreshButton') {
                     ActivateAlertDiv('visible', 'Processing....');
                function ActivateAlertDiv(visString, msg)
                     var adiv = $get(divElem);
                     var aspan = $get(messageElem);
            = visString;
                     aspan.innerHTML = msg;
            <div class="Container" >
            <asp:UpdatePanel  ID="UpdatePanel1" UpdateMode="Conditional" runat="Server"  >
                    <asp:Panel ID="Panel1" runat="server" GroupingText="UpdatePanel" 
                        Last update: 
                        <%=DateTime.Now.ToString() %>.
                        <asp:Button runat="server" ID="RefreshButton" Text="Refresh"
                            OnClick="ButtonClick_Handler" />
                        <div id="AlertDiv" class="AlertStyle">
                        <span id="AlertMessage"></span> &nbsp;&nbsp;&nbsp;&nbsp;
                        <asp:LinkButton ID="CancelRefresh" runat="server">cancel</asp:LinkButton>

Community Additions