Skip to main content

ASPxClientCardView.CustomButtonClick Event

Occurs when a custom command button has been clicked.

Declaration

CustomButtonClick: ASPxClientEvent<ASPxClientCardViewCustomButtonEventHandler<ASPxClientCardView>>

Event Data

The CustomButtonClick event's data class is ASPxClientCardViewCustomButtonEventArgs. The following properties provide information specific to this event:

Property Description
buttonID Gets the value which identifies the custom button.
processOnServer Specifies whether or not to process the event on the server. Inherited from ASPxClientProcessingModeEventArgs.
visibleIndex Gets the value which identifies the card whose custom button has been clicked.

Remarks

Handle the CustomButtonClick event to define an action for a custom button.

The event parameter’s ASPxClientCardViewCustomButtonEventArgs.buttonID property allows you to identify a button currently being clicked.

If the ASPxClientProcessingModeEventArgs.processOnServer property is set to true, the ASPxCardView.CustomButtonCallback event is raised, which allows you to perform server-side event processing.

Example

The following example handles the CommandButtonInitialize and CustomButtonInitialize events to specify the CommandButtons and CustomCommandButtons properties. The DataRow’s VisibleIndex property and criteria (set based on field values) are used to determine button visibility.

<dx:ASPxCardView ID="ASPxCardView1" runat="server" DataSourceID="AccessDataSource1"         
    OnCustomButtonInitialize="ASPxCardView1_CustomButtonInitialize" 
    OnCommandButtonInitialize="ASPxCardView1_CommandButtonInitialize" 
    KeyFieldName="ProductID" AutoGenerateColumns="False">
    <ClientSideEvents CustomButtonClick="function(s, e) {alert('keyValue = ' + s.GetCardKey(e.visibleIndex));}" />
    <SettingsBehavior AllowFocusedCard="true" />
    <Columns>
        <dx:CardViewTextColumn FieldName="ProductName" />
        <dx:CardViewTextColumn FieldName="UnitPrice" />
        <dx:CardViewTextColumn FieldName="ProductID" ReadOnly="True">
    </Columns>
    <CardLayoutProperties>
        <Items>
            <dx:CardViewCommandLayoutItem HorizontalAlign="Right" 
                                          ShowDeleteButton="True" 
                                          ShowEditButton="True" />
            <dx:CardViewColumnLayoutItem ColumnName="ProductID" />
            <dx:CardViewColumnLayoutItem ColumnName="Product Name" />
            <dx:CardViewColumnLayoutItem ColumnName="UnitPrice" />
        </Items>
    </CardLayoutProperties>
</dx:ASPxCardView>  
protected void Page_Load(object sender, EventArgs e) {
    if (!IsPostBack) {
        (ASPxCardView1.CardLayoutProperties.Items[0] as CardViewCommandLayoutItem).CustomButtons.Add(CreateCustomButton());
    }
}
CardViewCustomCommandButton CreateCustomButton() {
    CardViewCustomCommandButton customBtn = new CardViewCustomCommandButton();
    customBtn.ID = "CustomBtn";
    customBtn.Text = "Custom button";
    return customBtn;
}
protected void ASPxCardView1_CommandButtonInitialize(object sender, ASPxCardViewCommandButtonEventArgs e) {
    if (e.VisibleIndex == -1) return;
    switch (e.ButtonType) {
        case CardViewCommandButtonType.Edit:
            e.Visible = EditButtonVisibleCriteria((ASPxCardView)sender, e.VisibleIndex);
            break;
        case CardViewCommandButtonType.Delete:
            e.Visible = DeleteButtonVisibleCriteria((ASPxCardView)sender, e.VisibleIndex);
            break;
    }
}
private bool EditButtonVisibleCriteria(ASPxCardView grid, int visibleIndex) {
    object card = grid.GetDataRow(visibleIndex);
    return ((DataRow)card)["ProductName"].ToString().Contains("a");
}
private bool DeleteButtonVisibleCriteria(ASPxCardView grid, int visibleIndex) {
    object card = grid.GetDataRow(visibleIndex);
    return ((DataRow)card)["ProductName"].ToString().Contains("b");
}
protected void ASPxCardView1_CustomButtonInitialize(object sender, ASPxCardViewCustomCommandButtonEventArgs e) {
    if (e.VisibleIndex == -1) return;
    if (e.ButtonID == "CustomBtn" && e.VisibleIndex % 2 != 0)
        e.Visible = DefaultBoolean.False;
}
See Also