方法一
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=);
From:http://tw.wingwit.com/Article/program/net/201311/11924.html