Skip to content

Instantly share code, notes, and snippets.

@peyangu
Created March 17, 2017 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peyangu/73d130c33546258fa51806a82044abc3 to your computer and use it in GitHub Desktop.
Save peyangu/73d130c33546258fa51806a82044abc3 to your computer and use it in GitHub Desktop.
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