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 ?
protected void btnConfirm_Click(object sender, EventArgs e)
{
(guessing that there should be an input here)
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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");
}
Method 2
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"
Method 3
u can use this:
protected void btnConfirm_Click(object sender, EventArgs e)
{
Response.Redirect("Confirm.aspx");
}
Method 4
<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>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0