简体   繁体   中英

How can I server.transfer to one page and then server.transfer back to the original

How can I transfer to a confirmation page using:

    protected void Transfer_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            Server.Transfer("~/NewApplicationConfirmation.aspx");
        }
    }

Then, on the new page (NewApplicationConfirmation.aspx) transfer back to the original page if a user clicks edit:

    protected void Edit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            Server.Transfer("~/NewApplication.aspx");
        }
    }

When I click Edit now, it just blanks out all the data in NewApplicationConfirmation.aspx and doesn't change back to NewApplication.aspx

Notes:

--the address at the top does not change from /NewApplication when I do the first server transfer AND the address at the top does change to /NewApplicationConfirmation when I click edit

--I am using ASP.net 4.5 c#

--FriendlyURLs is installed (by default)

--I am using a master page on both pages

EDIT Additional info:

When I do my first transfer I use

var cp = PreviousPage.Master.FindControl("MainContent") as ContentPlaceHolder; 
TextBox PrevinputAppName = cp.FindControl("inputAppName") as TextBox;
inputAppName.Text = PrevinputAppName.Text; 

to find the controls. How do I transfer these back to the original page? Also note, when I do my second server.transfer, the confirmation page shows up blank -- the newapplication.aspx page doesn't appear in the browser

You can use page name in session value when you move to redirect page, put current page name in session and when you click on back than use session value to redirect previous page. After complete your work make session null.

protected void Transfer_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            Server.Transfer("~/NewApplicationConfirmation.aspx?page=NewApplication");
        }
    }
    protected void Edit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            Server.Transfer(Request.QueryString["page"] + ".aspx");
        }
    }

Use this if you want to use session variable, which i have mentioned below:

protected void Transfer_Click(object sender, EventArgs e)
{
    if (Page.IsValid)
    {
        Session["page"]="NewApplication.aspx";
        Server.Transfer("~/NewApplicationConfirmation.aspx");
    }
}
protected void Edit_Click(object sender, EventArgs e)
{
    if (Page.IsValid)
    {
        Server.Transfer(Session["page"].ToString());
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM