How to launch another aspx web page upon button click?

后端 未结 5 1833
醉梦人生
醉梦人生 2020-12-09 18:45

I have an asp.net application, where the user would click a button and launch another page (within the same application). The issue I am facing is that the original page an

相关标签:
5条回答
  • 2020-12-09 19:11

    This button post to the current page while at the same time opens OtherPage.aspx in a new browser window. I think this is what you mean with ...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');" />
    
    0 讨论(0)
  • 2020-12-09 19:24

    If you'd like to use Code Behind, may I suggest the following solution for an asp:button -

    ASPX Page

    <asp:Button ID="btnRecover" runat="server" Text="Recover" OnClick="btnRecover_Click" />
    

    Code Behind

        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();
        }
    
    0 讨论(0)
  • 2020-12-09 19:28

    Use an html button and javascript? in javascript, window.location is used to change the url location of the current window, while window.open will open a new one

    <input type="button" onclick="window.open('newPage.aspx', 'newPage');" />
    

    Edit: Ah, just found this: If the ID of your form tag is form1, set this attribute in your asp button

    OnClientClick="form1.target ='_blank';"
    
    0 讨论(0)
  • 2020-12-09 19:29

    Edited and fixed (thanks to Shredder)

    If you mean you want to open a new tab, try the below:

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Form.Target = "_blank";
    }
    
    protected void Button1_Click(object sender, EventArgs e)
    {
    
        Response.Redirect("Otherpage.aspx");
    }
    

    This will keep the original page to stay open and cause the redirects on the current page to affect the new tab only.

    -J

    0 讨论(0)
  • 2020-12-09 19:30

    You should use:

    protected void btn1_Click(object sender, EventArgs e)
    {
        Response.Redirect("otherpage.aspx");
    }
    
    0 讨论(0)
提交回复
热议问题