方法一 protected void Page_Load(object sender EventArgs e) { formTarget = _blank; } protected void Button_Click(object sender EventArgs e) { ResponseRedirect(); } 办法二采用客户端脚本的方法设置 target 属性代码如下 复制 保存 protected void Page_Load(object sender EventArgs e) { ButtonAttributesAdd(onclick thisformtarget=_newName); } protected void Button_Click(object sender EventArgs e) { ResponseRedirect(); } 方法三 protected void Page_Load(object sender EventArgs e) { string WindowName = win + SystemDateTimeNowTicksToString(); PageRegisterOnSubmitStatement(js windowopen( + WindowName + width=height=)); formTarget = WindowName; } protected void Button_Click(object sender EventArgs e) { ResponseRedirect(); } 方法 public static class ResponseHelper { public static void Redirect(string url string target string windowFeatures) { HttpContext context = HttpContextCurrent; if ((StringIsNullOrEmpty(target) || targetEquals(_self StringComparisonOrdinalIgnoreCase)) && StringIsNullOrEmpty(windowFeatures)) { contextResponseRedirect(url); } else { Page page = (Page)contextHandler; if (page == null) { throw new InvalidOperationException(Cannot redirect to new window outside Page context); } url = pageResolveClientUrl(url); string script; if (!StringIsNullOrEmpty(windowFeatures)) { script = @<script>windowopen({} {} {});</script>; } else { script = @<script>windowopen({} {});</script>; } script = StringFormat(script url target windowFeatures); //ScriptManagerRegisterStartupScript(page typeof(Page) Redirect script true); pageRegisterStartupScript(ddd script); } } } 调用 ResponseHelperRedirect(popupaspx _blank menubar=width=height=); |