I have a gridview inside an updatepanel. One of the fields in the gridview is an ASP.net linkbutton
like so:
<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 I call the OnClick
method that I created called LoadLog
.
LoadLog looks like this:
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 handle of the grid view row, pulls some data back from the database and assigns it to the gvLog source. After that notice 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 have to do this so that I can open up my dialog box. When I click a row in my gridview ONLY the first time I get this:
Notice it only really shows the title...weird. But once I click that same row again it shows the entire dialog:
It only happens on the first click, if I keep clicking different rows it works fine. I should 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();
// re-bind your jQuery events here
});
....more code...
Based on this discussion: jQuery $(document).ready and UpdatePanels?
If I do not have that code the minute a post back happens the entire div that this dialog is inside always gets shown on my page and I dont want that...
As one of the members below has mentioned. I believe what is happening is the first time you click the linkbutton the client side event is happening first which is opening the actual open dialog, even though I raise this event in server side code...as you see above only when you click the "LoadLog" event click do I register this jquery opendialog. But it appears that this still opens the dialog the first time and once you click it the second time only then is the data shown.