我有一个asp.net应用程序,用户可以单击按钮并启动另一个页面(在同一个应用程序中)。我面临的问题是原始页面和新启动的页面都应该启动。
我尝试了response.redirect,但这往往会卸载原始页面。
有什么建议吗?
答案 0 :(得分:29)
此按钮发布到当前页面,同时在新的浏览器窗口中打开OtherPage.aspx
。我认为这就是你对...the original page and the newly launched page should both be launched.
<asp:Button ID="myBtn" runat="server" Text="Click me"
onclick="myBtn_Click" OnClientClick="window.open('OtherPage.aspx', 'OtherPage');" />
答案 1 :(得分:13)
编辑并修复(感谢Shredder)
如果您的意思是要打开新标签页,请尝试以下操作:
protected void Page_Load(object sender, EventArgs e)
{
this.Form.Target = "_blank";
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Otherpage.aspx");
}
这将使原始页面保持打开状态,并导致当前页面上的重定向仅影响新选项卡。
-J
答案 2 :(得分:6)
如果您想使用Code Behind,我可以为asp建议以下解决方案:按钮 -
ASPX页面
<asp:Button ID="btnRecover" runat="server" Text="Recover" OnClick="btnRecover_Click" />
背后的代码
protected void btnRecover_Click(object sender, EventArgs e)
{
var recoveryId = Guid.Parse(lbRecovery.SelectedValue);
var url = string.Format("{0}?RecoveryId={1}", @"../Recovery.aspx", vehicleId);
// Response.Redirect(url); // Old way
Response.Write("<script> window.open( '" + url + "','_blank' ); </script>");
Response.End();
}
答案 3 :(得分:2)
您应该使用:
protected void btn1_Click(object sender, EventArgs e)
{
Response.Redirect("otherpage.aspx");
}
答案 4 :(得分:1)
使用html按钮和javascript?在javascript中,window.location
用于更改当前窗口的网址位置,而window.open
将打开一个新网址
<input type="button" onclick="window.open('newPage.aspx', 'newPage');" />
编辑:啊,刚发现这个:如果您的表单标记的ID是form1
,请在您的asp按钮中设置此属性
OnClientClick="form1.target ='_blank';"