ASP.NET和C#重定向 [英] ASP.NET and C# Redirect
问题描述
我工作的学校的一个项目,这是一个额外信贷的一部分。我有一个项目在VS 2010中开始使用母版页和我想要做的就是一个提交按钮,以人重定向到MyAccounts.aspx的页面。我现在的code的ASP一部分的按钮看起来是这样的:
I am working on a project for school, and this is an extra credit part. I have a project started in VS 2010 using master pages, and what I'm trying to do is get a "Submit" button to redirect people to the "MyAccounts.aspx" page. My current code for the ASP part for the button looks like this:
< ASP:按钮的ID =btnTransfer=服务器文本=提交/>
我曾尝试添加在的OnClick
选项,还有的OnClientClick
选项。我还添加了这个$ C $ C到Site.Master.cs文件,并在文件Transfer.aspx.cs:
I have tried adding in the OnClick
option, as well as the OnClientClick
option. I have also added this code to the Site.Master.cs file as well as the Transfer.aspx.cs file:
protected void btnTransfer_Click(object sender, EventArgs e)
{
Response.Redirect(Page.ResolveClientUrl("/MyAccounts.aspx"));
}
当我运行这个并查看该项目在我的浏览器,整个事情运行正常,但是当我点击提交按钮,它只是刷新当前页面并不能正确重定向到MyAccounts页面。任何人有任何想法我吗?
When I run this and view the project in my browser, the whole thing runs fine, but when I click on the "Submit" button, it just refreshes the current page and does not properly redirect to the MyAccounts page. Anyone have any ideas for me?
推荐答案
您几乎做正确,你只是还没有把正确的拼凑。在Transfer.aspx,你的按钮应该是:
You are doing it almost correctly, you just haven't put the correct pieces together. On Transfer.aspx, your button should be:
<asp:Button ID="btnTransfer" OnClick="btnTransfer_Click" runat="server" Text="Submit"/>
和您的code后面应该像什么@KendrickLamar说:
and your code behind should be like what @KendrickLamar said:
protected void btnTransfer_Click(object sender, EventArgs e)
{
Response.Redirect("~/MyAccounts.aspx");
}
的的OnClick
事件告诉它如何在回后执行时,用户点击这个按钮。这是在code-背后Transfer.aspx,不是网站的主人。
The OnClick
event tells it what to execute on post-back when the users clicks the button. This is in the code-behind for Transfer.aspx, not the site master.
这篇关于ASP.NET和C#重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!