页面刷新或页面返回后重新启动jQuery对话框

时间:2013-08-05 06:16:24

标签: jquery asp.net jquery-ui gridview jquery-ui-dialog

我有一个带有ButtonField的GridView,它显示每行的项目ID。

当用户点击项目ID(ButtonField)时,它会打开一个jQuery模式对话框,其中包含项目的更详细视图。当用户关闭对话框时(使用右上角的X),对话框关闭,一切都很棒。

问题是:如果用户刷新页面,或者转到新页面然后使用后退按钮返回,则页面会在已打开的对话框中刷新/重新打开。它应该保持关闭。

你能从我的代码中看出我做错了吗?


的javascript:

// set the <div> "dialog-projectDetails" as a jQuery modal dialog.
$(function () {
             $("#dialog-projectDetails").dialog({ autoOpen: false,
                                                  modal: true,
                                                  resizable: false});
});

asp:GridView - 我遗漏了大部分样式:

<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource2" DataKeyNames="ProjID"
EnableModelValidation="True" onRowCommand="GridView3_RowCommand">
<Columns>
    <%-- Link ButtonType on ProjID to activate modal pop-up --%>
    <asp:ButtonField 
        DataTextField="ProjID" 
        HeaderText="&nbsp;&nbsp;Proj. Id" 
        ShowHeader="True" SortExpression="ProjID"
        ButtonType="Link" CommandName="Select">
    </asp:ButtonField>

    <asp:BoundField 
        DataField="Projects" 
        HeaderText="Projects"
        SortExpression="Projects">
    </asp:BoundField>

    <asp:BoundField 
        DataField="Status" 
        HeaderText="Status"
        SortExpression="Status">
    </asp:BoundField>
</Columns>
</asp:GridView> <!-- end GridView3 -->

代码背后:

protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
 {
    if (e.CommandName == "Select")
    {
        int rowIndex = Convert.ToInt32(e.CommandArgument);
        // Retrieve the row that contains the button clicked.
        GridViewRow row = GridView3.Rows[rowIndex];
        string projectID = GridView3.DataKeys[row.RowIndex].Value.ToString();
        SqlDataSourceProjectComments.SelectParameters["ProjectID"].DefaultValue = projectID;

        string scriptText = "<script type = 'text/javascript'> $(function(){$('#dialog-projectDetails').dialog('open');})</script>";
        ClientScript.RegisterClientScriptBlock(this.GetType(), "DisplayProjectDetails", scriptText);
    }
 }

感谢您的任何建议。

0 个答案:

没有答案