Coder Social home page Coder Social logo

devexpress-examples / asp-net-web-forms-grid-validate-cell-values-on-server-in-batch-mode Goto Github PK

View Code? Open in Web Editor NEW
0.0 55.0 1.0 45 KB

Pass an editor's value to the server in batch edit mode, validate the value based on a condition, and pass the validation result to the client.

License: Other

C# 50.58% ASP.NET 49.42%
dotnet aspxgridview asp-net batch-editing callback editor validation

asp-net-web-forms-grid-validate-cell-values-on-server-in-batch-mode's Introduction

Grid View for ASP.NET Web Forms - How to validate entered cell values on the server in batch edit mode

This example demonstrates how to pass an editor's value to the server in batch edit mode, validate the value based on a condition, and pass the validation result to the client.

Invalid cell values in batch mode

Overview

Create the Grid View control and add a callback control to the page. For particular grid columns, specify their edit settings and handle client-side TextChanged events. In the handler, get an editor's value and call the callback's PerformCallback method to pass the value to the server.

var editor;
function OnTextChanged(s, e) {
    editor = s;
    clb.PerformCallback(fieldName + '|' + s.GetText());
    // ...
}
<dx:ASPxGridView ID="Grid" ClientInstanceName="grid" runat="server" KeyFieldName="ID" ... >
    <Columns>
        <!-- ... -->
        <dx:GridViewDataTextColumn FieldName="C3">
            <PropertiesTextEdit>
                <ClientSideEvents TextChanged="OnTextChanged" KeyDown="OnKeyDown" />
                <!-- ... -->
            </PropertiesTextEdit>
        </dx:GridViewDataTextColumn>
        <!-- ... -->
    </Columns>
    <SettingsEditing Mode="Batch" />
</dx:ASPxGridView>
<dx:ASPxCallback ID="ASPxCallback1" runat="server" ClientInstanceName="clb" OnCallback="ASPxCallback1_Callback">
    <ClientSideEvents CallbackComplete="OnCallbackComplete" />
</dx:ASPxCallback>

Handle the callback's server-side Callback event. In the handler, specify error text strings for invalid cells based on a condition and save these text strings to the e.Result argument property. Then pass the result to the callback's client-side CallbackComplete event to complete validation on the client.

var isError = false;
function OnCallbackComplete(s, e) {
    // ...
    if (e.result != null) {
        grid.batchEditApi.StartEdit(currentIndex, grid.GetColumnByField(fieldName).index);
        editor.SetIsValid(false);
        editor.SetErrorText(e.result);
        isError = true;
    }
    else
        isError = false;
}
protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e) {
    string[] parameters = e.Parameter.Split('|');
    switch (parameters[0]) {
        case "C3":
            if (parameters[1] == "AAA")
                e.Result = string.Format("'{0}' is invalid value", parameters[1]);
            break;
        case "C5":
            if (parameters[1] == "BBB")
                e.Result = string.Format("'{0}' is invalid value", parameters[1]);
            break;             
        default:
            break;
    }
    // ...
}

Files to Review

Documentation

asp-net-web-forms-grid-validate-cell-values-on-server-in-batch-mode's People

Contributors

devexpressexamplebot avatar elenapeskova avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

elenapeskova

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.