I have a gridview inside the update panel. One of the gridview fields is ASP.net linkbutton as follows:
<ItemTemplate> <asp:LinkButton ID="hlSortOrder" runat="server" CssClass="hlDialog" OnClick="LoadLog" Text='<%# DataBinder.Eval(Container, "DataItem.SortOrder") %>'></asp:LinkButton> </ItemTemplate>
When someone clicks the linkbutton button, I call the OnClick method that I created is called LoadLog . LoadLog is as follows:
protected void LoadLog(object sender, EventArgs e) { GridViewRow gr = (GridViewRow)((DataControlFieldCell)((LinkButton)sender).Parent).Parent; Label l = (Label)gr.FindControl("lblID"); DataSet ds; ds = BL.GetRunoffAnswerLog(Convert.ToInt64(l.Text)); if (ds != null) { if (ds.Tables[0].Rows.Count == 0) { gvLog.Visible = false; gvLog.DataSource = null; lblRowsCount.Text = "No log for this record!"; } else { lblRowsCount.Text = ds.Tables[0].Rows.Count.ToString() + " row(s) found for this record."; gvLog.DataSource = ds.Tables[0]; gvLog.DataBind(); gvLog.Visible = true; } } ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "openDialog", "$('#dialog').dialog({draggable: true, modal: true, height: 500, width: 750, title: 'Log', open: function (type, data) {$(this).parent().appendTo('form');}});", true); }
Basically, it gets a grid line descriptor, pulls some data from the database, and assigns it to the gvLog source. After that, pay attention to the line at the end:
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "openDialog", "$('#dialog').dialog({draggable: true, modal: true, height: 500, width: 750, title: 'Log', open: function (type, data) {$(this).parent().appendTo('form');}});", true);
I need to do this so that I can open my dialog box. When I click a row in my gridview ONLY for the first time, I get the following:

Please note that this really shows the name ... weird. But as soon as I click on the same line again, it will display the entire dialog:

This only happens on the first click, if I keep clicking on different lines, it works fine. I have to add that I had to add the following jquery code:
<script type="text/javascript"> $(document).ready(function () { var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_endRequest(function () { $("#dialog").hide();
Based on this discussion: jQuery $ (document) .ready and UpdatePanels?
If I do not have this code at the moment the answer appears, the entire div that is inside this dialog is always displayed on my page, and I do not want this ...
As one of the following members mentioned. I believe that the first time you click the linkbutton button, a client-side event occurs that opens the actual open dialog, although I raise this server-side event ... as you see above, only when you click the "LoadLog" Event button click to register this jQuery opendialog. But it looks like it still opens a dialog for the first time, and as soon as you click on it a second time, only then the data is displayed.