电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

使用Response.Redirect打开新窗口的方法


发布日期:2023/7/15
 

方法一

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=);

上一篇:何时使用DataGrid、DataList 或Repeater

下一篇:获得DataGridViewCheckBoxColumn的状态