[英]How do I redirect to another page with ASP.NET?
I know it's a simple question but I really can't find anything on Google. 我知道这是一个简单的问题但我在Google上找不到任何东西。 Sorry if I'm not searching right.
对不起,如果我没有正确搜索。 I created 2 pages and in the first one I have a button.
我创建了2页,在第一页中我有一个按钮。
What should I write in the C# code to change to redirect me on the second page? 我应该在C#代码中写什么来改变以在第二页上重定向我?
I usually know my way around C# but I'm totally new in ASP. 我通常知道我在C#的方式,但我是ASP的新手。
Add the button onclick event handler . 添加按钮onclick事件处理程序 。
In the event handler put: 在事件处理程序中放置:
Response.Redirect("YOUR_NEW_PAGE");
Response.Redirect or Server.Transfer Response.Redirect或Server.Transfer
Slightly more complicated, and probably not what you need a cross page post 稍微复杂一点,可能不是你需要的跨页帖子
Not quite sure from your question whether you're after ASP VB or C#...so... 从你的问题不太确定你是在使用ASP VB还是C#...所以......
// C# // C#
private void Button1_Click(object sender, System.EventArgs e)
{
Server.Transfer("Webform2.aspx");
}
' Visual Basic 'Visual Basic
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Server.Transfer("Webform2.aspx")
End Sub
For more information, I direct you to: 有关更多信息,请指导您:
http://msdn.microsoft.com/en-us/library/540y83hx%28VS.71%29.aspx http://msdn.microsoft.com/en-us/library/540y83hx%28VS.71%29.aspx
您也可以使用按钮的PostBackUrl属性在aspx本身(不编写任何代码)中执行此操作。
Use one of these methods: 使用以下方法之一:
One-time redirect (HTTP 301) 一次性重定向(HTTP 301)
Response.Redirect("page to redirect to");
Permanent redirect (HTTP 302), only available in ASP.NET 4.0 永久重定向(HTTP 302),仅在ASP.NET 4.0中可用
Response.RedirectPermanent("page to redirect to");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.