Skip to main content
A newer version of this page is available. .
Tab

CardViewClientSideEvents.CustomButtonClick Property

Gets or sets the name of the JavaScript function or the entire code which will handle a client ASPxCardView’s ASPxClientCardView.CustomButtonClick event.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v20.2.dll

NuGet Package: DevExpress.Web

Declaration

[DefaultValue("")]
public string CustomButtonClick { get; set; }

Property Value

Type Default Description
String String.Empty

A string that represents either the name of a JavaScript function or the entire JavaScript function code used to handle an event.

Example

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

View Example

<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="ProductID" VisibleIndex="2" ReadOnly="True">
        </dx:CardViewTextColumn>
        <dx:CardViewTextColumn FieldName="ProductName" VisibleIndex="0">
        </dx:CardViewTextColumn>
        <dx:CardViewTextColumn FieldName="UnitPrice" VisibleIndex="1">
        </dx:CardViewTextColumn>
    </Columns>
    <CardLayoutProperties>
        <Items>
            <dx:CardViewCommandLayoutItem HorizontalAlign="Right" ShowDeleteButton="True" ShowEditButton="True">
            </dx:CardViewCommandLayoutItem>
            <dx:CardViewColumnLayoutItem ColumnName="ProductID">
            </dx:CardViewColumnLayoutItem>
            <dx:CardViewColumnLayoutItem ColumnName="Product Name">
            </dx:CardViewColumnLayoutItem>
            <dx:CardViewColumnLayoutItem ColumnName="UnitPrice">
            </dx:CardViewColumnLayoutItem>                
        </Items>
    </CardLayoutProperties>        
</dx:ASPxCardView>  
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Utils;
using DevExpress.Web;

public partial class _Default : System.Web.UI.Page
{
    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