C# jquery对话框在回发时重新出现

C# jquery对话框在回发时重新出现,c#,jquery,C#,Jquery,我有一个GridView,其中一个TemplateField包含一个LinkButton。单击此按钮时,它会将另一个隐藏TemplateField中的某些XML转换为字符串,并将其指定给隐藏div中的标签,以便在模式对话框中使用。当前,对话框按预期打开并显示正确的信息,然后关闭,我可以在网格中选择另一条记录以查看,没有问题。这就是问题所在,我一直无法找到解决办法。如果我在页面上执行了导致回发的其他操作,则在加载新页面时将打开最后一个要打开的对话框 以下是我的相关加价: <scrip

我有一个GridView,其中一个TemplateField包含一个LinkButton。单击此按钮时,它会将另一个隐藏TemplateField中的某些XML转换为字符串,并将其指定给隐藏div中的标签,以便在模式对话框中使用。当前,对话框按预期打开并显示正确的信息,然后关闭,我可以在网格中选择另一条记录以查看,没有问题。这就是问题所在,我一直无法找到解决办法。如果我在页面上执行了导致回发的其他操作,则在加载新页面时将打开最后一个要打开的对话框

以下是我的相关加价:

    <script type="text/javascript">
$(document).ready(function() {
    $("#txtBeginDate").datepicker();
    $("#txtEndDate").datepicker();

    $("#response").dialog({
        autoOpen: false,
        modal: true,
        height: "auto",
        width: "auto",
        title: "Equifax Response",
        close: function(ev, ui) {
            $(this).dialog('destroy').remove();
        }
    });

    $("[id*=lnkEquifaxResponse]").on("click", function EquifaxResopnse() {
        $("#lblDialog").empty();
    });

    if ($("#lblDialog").text() != "") {
        $("#response").dialog("open");
    }
});
    </script>

    <div id="response" visible="false">
        <asp:Label ID="lblDialog" runat="server" ></asp:Label>
    </div>

    <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" 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>
            <PagerStyle CssClass="pgr" />
            <AlternatingRowStyle CssClass="alt" />
        </asp:GridView>
    </div>

$(文档).ready(函数(){
$(“#txtBeginDate”).datepicker();
$(“#txtEndDate”).datepicker();
$(“#响应”)。对话框({
自动打开:错误,
莫代尔:是的,
高度:“自动”,
宽度:“自动”,
标题:“Equifax响应”,
关闭:功能(ev、ui){
$(this.dialog('destroy').remove();
}
});
$(“[id*=LNKEQUIFASRESPONSE]”。在(“单击”上,函数EquifaxResopnse(){
$(“#lbldilog”).empty();
});
如果($(“#lbldilog”).text()!=”){
$(“#响应”)。对话框(“打开”);
}
});

我是编程新手,因此非常感谢您的帮助。

更新您的代码如下:

 <div id="response" visible="false">
    <asp:Label ID="lblDialog" runat="server" EnableViewState="False"></asp:Label>
 </div>
若您将添加enableviewstate=“false”,则lblDialog的内部文本将在第二次回发时丢失,并且在页面加载后标签将为空(若未单击网格中的链接)


您可以获得有关viewstate及其工作原理的更多信息

谢谢!成功了。我已经为此痛打了两天了。
if ($("#lblDialog").text() != "") {
    $("#response").dialog("open");
}