ASP.NET按钮单击重定向到新页面

Par*_*rag 5 c# asp.net

我以编程方式创建了一个Button.我现在想要点击这个按钮重定向到一个新的aspx页面,这样我们就会进入新页面的一个方法(比如page_load()等)

这可能吗?

例如:

Button oButton = new Button;
oButton.Text = "NextPage";
// Redirect to "Redirect.aspx" on click
Run Code Online (Sandbox Code Playgroud)

但我无法在Redirect.aspx中找到一个入口点,一旦我们重定向到"Redirect.aspx",我就可以对UI组件进行一些更改

问候,

Parag

ada*_*ost 6

你需要处理oButton的Click事件.

Button oButton = new Button();
 oButton.Text = "NextPage";
 oButton.Click += (sa, ea) =>
     {
         Response.Redirect("Redirect.aspx");
   };
Run Code Online (Sandbox Code Playgroud)


Waq*_*qas 2

您可以使用查询字符串参数,并根据参数的值调用适当的方法 ,Page_Load例如Redirect.aspx

Redirect.aspx?val=1
Run Code Online (Sandbox Code Playgroud)

在重定向.aspx 中

protected void Page_Load(...){
string var = Request.QueryString["val"];
if(var == "1")
some_method();
else
some_other_method();
}
Run Code Online (Sandbox Code Playgroud)