Why I am Getting Message at Every Click Event?

I want to display a message to a user, like this: Duplicate Value Not Allowed.

For that I am using jQuery. The first time it’s working as expected, but unfortunately the one-time message is displayed every time – it’s showing the same text. How can I prevent it?

.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;
}

I am Calling This Function On Grid View Updated Click

Grid:

<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 [email protected]", 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;
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The alert is shown based on the condition gvc.cpInsertNote != ""… So what about to empty it after the first alert?

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x