各行のプロジェクト ID を表示する ButtonField を持つ GridView があります。
ユーザーがプロジェクト 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=" 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);
}
}
提案をありがとう。