0

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); 
          
 
    }
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by stbuchok
0

In my experience, using UpdatePanels is extremely painful if you have almost any JavaScript on the page. I've found it much easier to use Page Methods and web services to accomplish the same effects but with smoother transitions and less communication with the server.

Also to make it easier for you, look at how to use @"" when building fairly large strings in C#. You should also check to see if the ScriptBlock is already registered before registering it again (especially with update panels on the page).

StringBuilder sb = new StringBuilder(); 
        sb.Append(@"$(function() { 
                        $('div[id$=""dialog""]').dialog({
                            modal: true,           
                            title: 'Message',
                            width: 300,
                        });
                    });");
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.