Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
showModalDialogの呼び出し時に親画面のスクロール位置が初期位置に戻ってしまうのを防ぐ
protected void Button1_Click(object sender, EventArgs e)
{
// 何かしらの処理
StringBuilder script = new StringBuilder();
// 重要なのは↓
script.Append("<script language='JavaScript'> if (WebForm_RestoreScrollPosition) WebForm_RestoreScrollPosition();");
script.Append("window.showModalDialog('hoge.aspx', window, 'dialogWidth: 300px; dialogHeight: 200px; center; scroll=0; status=0,location=0');</script>");
ClientScriptManager csMgr = Page.ClientScript;
csMgr.RegisterStartupScript(this.GetType(), "DoOpenScript", script.ToString(), false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment