Csh*_*arp 12 vb.net asp.net buttonclick
我有一个asp.net应用程序,用户可以在其中单击按钮并启动另一个页面(在同一个应用程序中).我面临的问题是原始页面和新启动的页面都应该启动.
我尝试了response.redirect,但这往往会卸载原始页面.
有什么建议?
Cla*_*edi 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');" />
Run Code Online (Sandbox Code Playgroud)
Kre*_*epN 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");
}
Run Code Online (Sandbox Code Playgroud)
这将使原始页面保持打开状态,并导致当前页面上的重定向仅影响新选项卡.
-J
如果您想使用Code Behind,我可以建议以下解决方案:asp:按钮 -
ASPX
<asp:Button ID="btnRecover" runat="server" Text="Recover" OnClick="btnRecover_Click" />
Run Code Online (Sandbox Code Playgroud)
代码背后
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();
}
Run Code Online (Sandbox Code Playgroud)