ASP.NET按钮单击重定向到新页面
我以编程方式创建了一个Button。 我现在想要点击这个按钮重定向到一个新的aspx页面,这样我们就会进入新页面的一个方法(比如page_load()等)
这可能吗?
例如:
Button oButton = new Button; oButton.Text = "NextPage"; // Redirect to "Redirect.aspx" on click
但我无法在Redirect.aspx中找到一个入口点,一旦我们重定向到“Redirect.aspx”,我就可以对UI组件进行一些更改
问候,
Parag
您可以使用查询字符串参数,并根据param的值调用Redirect.aspx
Page_Load
中的相应方法,例如
Redirect.aspx?val=1
在Redirect.aspx中
protected void Page_Load(...){ string var = Request.QueryString["val"]; if(var == "1") some_method(); else some_other_method(); }
你需要处理oButton的Click事件。
Button oButton = new Button(); oButton.Text = "NextPage"; oButton.Click += (sa, ea) => { Response.Redirect("Redirect.aspx"); };
您还可以使用Button
的PostBackUrl
属性 – 这将发布到指定的页面,如果您需要访问PreviousPage
项目,您可以使用PreviousPage
属性:
Button oButton = new Button; oButton.Text = "NextPage"; oButton.PostBackUrl = "Redirect.aspx";
然后你想从上一页的ID为txtMyInput
的TextBox
获取值,你可以这样做(非常简单的例子给你一个想法):
void Page_Load(object sender, EventArgs e) { string myInputText = ((TextBox)PreviousPage.FindControl("txtMyInput")).Text; // Do something with/based on the value. }
只是另一个如何实现我认为你所要求的例子。
有关详细信息,请参阅Button.PostBackUrl属性 。
- 无法使用FormsAuthentication.SignOut()从ASP.NET MVC应用程序注销
- 自定义身份validation的HttpModule如何与Windows身份validation交互?
- OWASP AppSensor在ASP.Net C#应用程序中的实现
- 当它使用的方法发生变化时,为什么需要重新编译页面?
- 使用reflection获取嵌套对象属性值
- 如何使用C#在代码后面的asp.net中编写javascript
- 如何解决错误:该类型似乎没有实现microsoft.practices.servicelocation.iservicelocator?
- .NET 4.0中的Response.Redirect
- 如何检测“保存/打开/取消”对话框中单击了哪个按钮?