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

ASPxCardView.CardInserted Event

Fires after a new card has been added to the ASPxCardView.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v19.2.dll

Declaration

public event ASPxDataInsertedEventHandler CardInserted

Event Data

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

Property Description
AffectedRecords Gets the number of records affected by the update operation. Inherited from ASPxDataBaseUpdatedEventArgs.
Exception Gets the exception (if any) that was raised during the update operation. Inherited from ASPxDataBaseUpdatedEventArgs.
ExceptionHandled Gets or sets whether an exception raised during the update operation was handled in the event handler. Inherited from ASPxDataBaseUpdatedEventArgs.
NewValues Gets a dictionary that contains the values of the non-key field name/value pairs in the row to be inserted.

Remarks

End-users can create new cards by clicking the New command. To create cards in code, use the ASPxCardView.AddNewCard method. To save the newly created card, end-users must click the Update command.

To cancel the insert operation, handle the ASPxCardView.CardInserting event.

Note

The CardInserted event fires even though an exception occurs during the data update operation. Use the ASPxDataBaseUpdatedEventArgs.Exception and ASPxDataBaseUpdatedEventArgs.ExceptionHandled argument properties to determine whether or not any exception occurs during the corresponding action, and handle it if you wish.

Example

To focus a newly inserted card, you need to know the card’s keyValue. You can handle the ASPxCardView.CardInserted event to get the value. This event is raised after a new card is added to the ASPxCardView data source.

Note

A complete sample project is available in the following repository: https://github.com/DevExpress-Examples/aspxcardview-how-to-focus-a-newly-inserted-card-t279422.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
using DevExpress.Xpo.Metadata;

/// <summary>
/// Summary description for XpoHelper
/// </summary>
public static class XpoHelper {
    static XpoHelper () {
        CreateDefaultObjects();
    }

    public static Session GetNewSession () {
        return new Session(DataLayer);
    }

    public static UnitOfWork GetNewUnitOfWork () {
        return new UnitOfWork(DataLayer);
    }

    private readonly static object lockObject = new object();

    static IDataLayer fDataLayer;
    static IDataLayer DataLayer {
        get {
            if (fDataLayer == null) {
                lock (lockObject) {
                    fDataLayer = GetDataLayer();
                }
            }
            return fDataLayer;
        }
    }

    private static IDataLayer GetDataLayer () {
        XpoDefault.Session = null;

        InMemoryDataStore ds = new InMemoryDataStore();
        XPDictionary dict = new ReflectionDictionary();
        dict.GetDataStoreSchema(typeof(Customer).Assembly);

        return new ThreadSafeDataLayer(dict, ds);
    }

    static void CreateDefaultObjects () {
        using (UnitOfWork uow = GetNewUnitOfWork()) {
            Customer cust = new Customer(uow);
            cust.CompanyName = "Alfreds Futterkiste";
            cust.ContactName = "Maria Anders";
            cust.Country = "Germany";

            cust = new Customer(uow);
            cust.CompanyName = "Ana Trujillo Emparedados y helados";
            cust.ContactName = "Ana Trujillo";
            cust.Country = "Mexico";

            cust = new Customer(uow);
            cust.CompanyName = "Antonio Moreno Taquería";
            cust.ContactName = "Antonio Moreno";
            cust.Country = "Mexico";

            cust = new Customer(uow);
            cust.CompanyName = "Blondel père et fils";
            cust.ContactName = "Frédérique Citeaux";
            cust.Country = "France";

            cust = new Customer(uow);
            cust.CompanyName = "Berglunds snabbköp";
            cust.ContactName = "Christina Berglund";
            cust.Country = "Sweden";

            cust = new Customer(uow);
            cust.CompanyName = "Bottom-Dollar Markets";
            cust.ContactName = "Elizabeth Lincoln";
            cust.Country = "Canada";

            uow.CommitChanges();
        }
    }
}
See Also