0

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

  • 1
    Regarding the url in the address bar not changing, it's not going to. That's what a transfer does. The server internally transfers execution to another page without telling the client. If you are trying to have the client go to a different page, you want `Response.Redirect("newpage.aspx");` – Russell Uhl Mar 25 '15 at 15:46
  • I understand, but can you server.transfer back to the original page? – Will Howard Mar 25 '15 at 15:47
  • yes. that's exactly what you're doing. and since (I assume) you're not passing along any parameters, when you transfer back to the original page, you're creating a fresh instance of it, which does not have your data – Russell Uhl Mar 25 '15 at 16:14
  • Please update your original question with that additional information. It will make things MUCH easier to read – Russell Uhl Mar 25 '15 at 16:35
  • My suggestions are that you use redirect instead of transfer, and that you familiarize yourself with GET vs POST, and QueryString vars vs Session vars – Russell Uhl Mar 25 '15 at 16:49
  • I prefer to do this w query string or session, but if you must... you need to do the same thing on the confirm page as you're doing on the edit page to get the identifying data back from the edit page. Obviously you'll want to check if you're coming from the edit page before calling FindControl on the confirm page. – RandomUs1r Mar 25 '15 at 16:49
  • If you're posting to another page and then returning, why not just use a regular postback and not leave the page? – Tim Mar 25 '15 at 16:59
  • This comment is going to show my .net newbieness, but the reason I am transferring to a new page is to show a very different page (so the user can review their application). How can I implement a very different markup, with the same values originally put into the controls, in the same page? – Will Howard Mar 25 '15 at 17:20

1 Answers1

0

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());
    }
}
  • Take a look at https://msdn.microsoft.com/en-us/library/6c3yckfw%28v=vs.140%29.aspx , he's using a different approach. – RandomUs1r Mar 25 '15 at 16:50
  • yes, you can use query string, but you are saying to not modify your url – Sunil Kumawat Mar 25 '15 at 16:52
  • Just pass your values in query string like ~/NewApplicationConfirmation.aspx?page=NewApplication and use this to back like Server.Transfer(Request.QueryString["page"]+".aspx"); – Sunil Kumawat Mar 25 '15 at 16:56
  • I have 50 variables passing. If I use the query string, I am worried about hitting the max characters. – Will Howard Mar 25 '15 at 17:16
  • do not worry about it. you can pass this. or you can use session variable as well. let me update my answer with session as well. – Sunil Kumawat Mar 25 '15 at 17:24
  • I have edited my answer, please verify. I hope this will helpful to you. – Sunil Kumawat Mar 25 '15 at 17:33
  • I still get the same results. The submit button transfer from the first page to the second page works (with filled in controls). The edit button transfer from the second page to the first page: does not move to the first page and redisplays the second page with the data removed from the controls. One note: I am using a master page with both pages. – Will Howard Mar 25 '15 at 18:22
  • If you want to refill your data again on back to page than you need to call data again from your database or need to save page in a session variable before move to next page. – Sunil Kumawat Mar 25 '15 at 18:44
  • Can you please give me an example of how to save my page asp controls into a session variable and then how to reference them on my next page (using a master page)? – Will Howard Mar 25 '15 at 18:49
  • You can see my above answer with session. In this I have stored a string value in session an use this on next page. First of all you need to know how to session work and how we can use it. – Sunil Kumawat Mar 26 '15 at 01:34
  • Yep, I have started passing all fields through session variables and it worked fine. – Will Howard Mar 31 '15 at 15:09