New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Attach the OnBlur event to NumericTextBox of GridNumericColumn

Environment

ProductRadGrid for ASP.NET AJAX

Description

How to attach the OnBlur Client-side event to the RadNumericTextBox of the Grid's built-in GridNumericColumn?

Solution

To do that, you will need to access the RadNumericTextBox of the GridNumericColumn in the ItemCreated event and set its ClientEvents.OnBlur property to the name of the JavaScript function you want it to call when it looses focus (on blur).

This approach applies to EditMode="InPlace".

Example Markup

ASP.NET
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateEditColumn="true" AutoGenerateDeleteColumn="true" 
    OnItemCreated="RadGrid1_ItemCreated" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView AutoGenerateColumns="false" InsertItemPageIndexAction="ShowItemOnLastPage" EditMode="InPlace">
        <Columns>
            <telerik:GridNumericColumn UniqueName="ColumnUniqueName" DataField="ColumnUniqueName" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

Accessing the NumericTextBox and attaching the attaching the OnBlur Client-side event to it.

C#
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = (GridDataItem)e.Item;

        if (dataItem.IsInEditMode)
        {
            RadNumericTextBox currentLumQuantityTextBox = dataItem["ColumnUniqueName"].Controls[0] as RadNumericTextBox; // Change the ColumnUniqueName to your column's actual unique name
            currentLumQuantityTextBox.ClientEvents.OnBlur = "handleBlur";
        }
    }
}

The JavaScript function that will be called upon loosing the focus (on blur)

JavaScript
<script>
    function handleBlur(sender, args) {
        // Execute some logic
    }
</script>
In this article
EnvironmentDescriptionSolution
Not finding the help you need?
Contact Support