jQuery Dialog closes immediately
asp.net, c#, jquery
Solution
jQuery's `live()` method has been deprecated and removed in version 1.9 and has been replaced with the `on()` method.
Therefore, replace this:
$("[id*=lnkEquifaxResponse]").live("click", function EquifaxResopnse() {
$("#response").dialog("open");
});
with this:
$("[id*=lnkEquifaxResponse]").on("click", function EquifaxResopnse() {
$("#response").dialog("open");
return false; // Prevents the postback
});
You can do this in a different manner:
$(document).ready(function() {
$("[id*=lnkEquifaxResponse]").on("click", function EquifaxResopnse() {
$("#lblDialog").empty();
});
if($("#lblDialog").text() != "")
{
$("#response").dialog("open");
}
});
Problem
I have a jQuery dialog box that closes immediately upon opening. It is set to a button located in a template field of a GridView. My JavaScript: ``` <script type="text/javascript"> $(document).ready(function() { $("#txtBeginDate").datepicker(); $("#txtEndDate").datepicker(); $("#response").dialog({ autoOpen: false, modal: true, title: "Equifax Response" }); $("[id*=lnkEquifaxResponse]").live("click", function EquifaxResopnse() { $("#response").dialog("open"); }); }); </script> ``` My relevant GridView markup: ``` <div id="Gridview"> <asp:GridView ID="grClientTransactions" runat="server" AllowPaging="True" PageSize="25" AutoGenerateColumns="False" DataKeyNames="ResponseXML" EmptyDataText="Record not found." EmptyDataRowStyle-BackColor="#CCCCCC" EmptyDataRowStyle-Font-Bold="true" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" OnPageIndexChanging="grClientTransactions_PageIndexChanging" onrowcommand="grClientTransactions_RowCommand"> <Columns> <asp:TemplateField ShowHeader="false"> <ItemTemplate> <asp:LinkButton ID="lnkEquifaxResponse" runat="server" CausesValidation="False" CommandName="EquifaxResponse" Text="View" CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>'> </asp:LinkButton> </ItemTemplate> </asp:TemplateField> <asp:TemplateField Visible="false" HeaderText="Equifax Response"> <ItemTemplate> <asp:Label ID="lblEquifaxResponse" runat="server" Text='<%# Bind("ResponseXML")%>' > </asp:Label></div> </ItemTemplate> </asp:TemplateField> </Columns> ``` My div that displays a label with an assigned string from CodeBehind: ``` <div id="response"> <asp:Label ID="lblDialog" runat="server" ></asp:Label> </div> ```