ASP.NET Button to redirect to another page

后端 未结 4 621
萌比男神i
萌比男神i 2020-12-05 10:08

How do I code the button such that when I click the button and it brings me to another web form? Let\'s say the button name is Confirm and the wed form is confirm.aspx ?

相关标签:
4条回答
  • 2020-12-05 10:16

    You can use PostBackUrl="~/Confirm.aspx"

    For example:

    In your .aspx file

    <asp:Button ID="btnConfirm" runat="server" Text="Confirm" PostBackUrl="~/Confirm.aspx" />

    or in your .cs file

    btnConfirm.PostBackUrl="~/Confirm.aspx"

    0 讨论(0)
  • 2020-12-05 10:16

    u can use this:

    protected void btnConfirm_Click(object sender, EventArgs e)
    {
      Response.Redirect("Confirm.aspx");
    }
    
    0 讨论(0)
  • 2020-12-05 10:33
    <button type ="button" onclick="location.href='@Url.Action("viewname","Controllername")'"> Button name</button>
    

    for e.g ,

    <button type="button" onclick="location.href='@Url.Action("register","Home")'">Register</button>
    
    0 讨论(0)
  • 2020-12-05 10:38

    You can either do a Response.Redirect("YourPage.aspx"); or a Server.Transfer("YourPage.aspx"); on your button click event. So it's gonna be like the following:

    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        Response.Redirect("YourPage.aspx");
        //or
        Server.Transfer("YourPage.aspx");
    }
    
    0 讨论(0)
提交回复
热议问题