I am using jQuery Dialog to show dialogs when preforming insert, delete and update operations in a GridView inside an UpdatePanel.
The problem is that there is a repetition when preforming more than one operation.
For example, when updating a record on the page for the first time, it only shows the dialog once (that is ok)
but if I do another update or delete a record it will show the previous dialog(the update dialog)/dialogs and then the delete dialog
and so on if I do another operation.
I think the problem is in the System.Web.UI.ScriptManager.RegisterClientScriptBlock, it register the javascript code with same name every time an event happens in the GridView.
How to solve this?
protected void dvInsertBranch_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
callDialog("insert successfully", dialog);
}
protected void gvBranches_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
callDialog("update successfully", dialog);
}
protected void gvBranches_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
callDialog("delete successfully", dialog);
}
protected void callDialog(String message, HtmlGenericControl control)
{
control.InnerHtml = message;
StringBuilder sb = new StringBuilder();
sb.Append("$(function() { ");
sb.Append("$('div[id$=\"dialog\"]').dialog({");
sb.Append("modal: true,");
sb.Append("title: 'Message',");
sb.Append("width: 300,");
sb.Append("});");
sb.Append("});");
System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(),"showDialog", sb.ToString(), true);
}