Active Query Builder support area

How to prevent removing objects and fields from the query in ASP.NET Edition?

Last modified:

It is possible to deny removing datasources and uncheck fields from the query both server-side and client-side. Client-side checks allow for smoother user experience while server-side checks can be made for safety reasons and for checking manual changes to the query text.


var queryBuilder;
var required = {
    table: 'Orders', field: { name: "OrderID", expression: "o.OrderID" }

AQB.Web.onQueryBuilderReady(function (qb) {
    queryBuilder = qb;
    qb.on(qb.Events.DataSourceDeleting, onDataSourceDeleting);
    qb.on(qb.Events.DataSourceFieldRemoving, onDataSourceFieldRemoving);

function onDataSourceDeleting(dataSource, abort) {
    if (isMainQuery() && dataSource.mdo.Name === required.table) {
        abort.abort = true;
        queryBuilder.StatusBarComponent.messageWarning('Removing the required table is locked.');

function onDataSourceFieldRemoving(field, abort) {
    if (isMainQuery() &&
        field.field &&
        field.field.object.NameStr === &&
        field.table.Name === required.table) {
        abort.abort = true;
        queryBuilder.StatusBarComponent.messageWarning('Removing the required field is locked.');

function isMainQuery() {
    return queryBuilder.ActiveSubQueryPath.length === 0;

The full list of client-side events can be found in the documentation: AQB ASP.NET 3 - JavaScript API Documentation.

You can perform much deeper checks by analyzing the query server-side. Server-side events are listed here: AQB ASP.NET 3 - Server-side Objects Reference

Please review the "Verifying Query Elements" and "Query Analysis" demos in the C# MVC demo project for .NET Framework and ASP.NET Core. These demos are included in the installation package and available on GitHub:

Demos for .NET Framework:

Demos for ASP.NET Core:


Is this article helpful for you?