为什么每次点击事件我都会收到消息?

Why I am Getting Message at Every Click Event?

我想向用户显示一条消息,如下所示:Duplicate Value Not Allowed

为此,我正在使用 jQuery。第一次它按预期工作,但不幸的是每次都显示一次性消息 - 它显示相同的文本。我该如何预防?

.JS

function OnEndCallback() {
    if (gvc.cpInsertNote == undefined || gvc.IsNewItemEditing() || gvc.IsEditing() ) {
        // Egnore   || gvc.IsNewItemEditing ||gvc.IsEditing
    }
    else {
        if (gvc.cpInsertNote != "") {
            alert(gvc.cpInsertNote);
        }
    }
    // return false;
}

我在网格视图更新点击时调用此函数

网格:

<Templates>
    <DetailRow>
        <dx:ASPxGridView ID="dgCustomers" runat="server" KeyFieldName="CustomerLineItemID" OnBeforePerformDataSelect="dgCustomers_BeforePerformDataSelect"
        OnDataBinding="dgCustomers_DataBinding" ClientInstanceName="gvc"
        Width="100%" OnRowDeleting="dgCustomers_RowDeleting" OnRowInserting="dgCustomers_RowInserting"
        OnRowUpdating="dgCustomers_RowUpdating" CellStyle-HorizontalAlign="Center">
            <ClientSideEvents EndCallback="OnEndCallback" />
                <Columns>
                    ...

.CS

int CustomerCount = 0;
SqlCommand cmddupCust = new SqlCommand("select count(*) from GA_LineItemsCustomers where CustomerCode = @CustomerCode and LineItemID=@LineItemID", con);
cmddupCust.Connection = con;
cmddupCust.CommandType = System.Data.CommandType.Text;
cmddupCust.Parameters.AddWithValue("@CustomerCode", CustomerCode);
cmddupCust.Parameters.AddWithValue("@LineItemID", LineItemID);
con.Open();
CustomerCount = Convert.ToInt32(cmddupCust.ExecuteScalar());
con.Close();

if (CustomerCount > 0)
{
    ((ASPxGridView)sender).JSProperties["cpInsertNote"] = "Duplicate Entries Not Allowed";
    e.Cancel = true;
    return;
}

警报是根据条件显示的gvc.cpInsertNote != ""...所以在第一次警报后清空它怎么样?

if (gvc.cpInsertNote != "") {
  alert(gvc.cpInsertNote);
  gvc.cpInsertNote = "";  // Add this
}