当我点击C#(Web部件)中的"取消"按钮时,重定向到新页面

本文关键字:quot 取消 按钮 新页面 重定向 中的 部件 Web | 更新日期: 2023-09-27 17:59:59

// Cancel button
            tc = new TableCell();
            btnCancel = new Button();
            btnCancel.Text = "Cancel";
            btnCancel.Click += new EventHandler (btnCanel_Click ) ;
            tc.Controls.Add(btnCancel);
            tr.Controls.Add(tc);
            t.Controls.Add(tr);

            // Empty table cell
            tr = new TableRow();
            tc = new TableCell();
            tr.Controls.Add(tc);
            this.Controls.Add(t);
        }
        protected void btnCanel_Click(object sender, EventArgs e)
        {
        }

我想做的是。当我点击"取消"按钮时,它会将我重定向到"Example.aspx"。我正在使用C#创建一个Web部件

当我点击C#(Web部件)中的"取消"按钮时,重定向到新页面

protected void btnCanel_Click(object sender, EventArgs e)
{
    Response.Redirect("example.aspx");
}

要在服务器上做你想做的事情,应该是Response.Redirect。不过不需要回发。有一些客户端解决方案。使用LinkButton,w/onclick-html属性设置为false。不过,我的建议是这样的:

<INPUT TYPE="BUTTON" VALUE="Cancel" ONCLICK="window.location.href='http://www.yourdomain.com/example.aspx'"> 

调用HttpResponse.RRedirect方法。

示例:

Response.Redirect("Example.aspx");