ASP.NET按钮重定向到另一个页面

use*_*048 34 asp.net webforms button visual-studio-2013

如何对按钮进行编码,以便在单击按钮时将其带到另一个Web表单?假设按钮名称为Confirm,结婚格式为confirm.aspx?

    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        (guessing that there should be an input here)
    }
Run Code Online (Sandbox Code Playgroud)

Rex*_*Rex 48

您可以执行按钮单击事件Response.Redirect("YourPage.aspx");Server.Transfer("YourPage.aspx");按钮单击事件.所以它会像下面这样:

protected void btnConfirm_Click(object sender, EventArgs e)
{
    Response.Redirect("YourPage.aspx");
    //or
    Server.Transfer("YourPage.aspx");
}
Run Code Online (Sandbox Code Playgroud)


小智 12

您可以使用 PostBackUrl="~/Confirm.aspx"

例如:

在.aspx文件中

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

或者在.cs文件中

btnConfirm.PostBackUrl="~/Confirm.aspx"

  • 检查这个https://www.daniweb.com/web-development/aspnet/threads/69851/postbackurl-vs-response-redirect基本上PostBackUrl意味着与同一服务器一起使用,因为它将保存viewState.Response.Redirect可以带您到全新的会话将开始的全新服务器/网站 (5认同)

小智 6

你可以用这个:

protected void btnConfirm_Click(object sender, EventArgs e)
{
  Response.Redirect("Confirm.aspx");
}
Run Code Online (Sandbox Code Playgroud)