简体   繁体   中英

Server.Transfer does not work

After lots of research still I do not have an answer.

I use WebForm app VS 2013.

My code is fairly simple:

Server.Transfer("~/Success.aspx",true);

After this, load event of Success.aspx is executed but in the browser I only see original Main form.

I created any empty Web Form with only a Button on it but after running the following code

  Server.Transfer("~/WebForm2.aspx",true);

still I see MainForm.aspx,(Page_load event handler of WebForm2 runs)

==========================

Update per IrishGrifgin's comments.

I indeed have aJax in my code. I do have UpdatePanels which use Ajax.If this is the problem for server.Transfer how can we resolve this?

I don't think you understand what Server.Transfer() does.

It temporarily redirects the code to run the code in the second page.. but it returns control back to the original page once complete. It's entirely possible that the browser won't get (or see) the html from the second page.

See https://msdn.microsoft.com/en-us/library/ms525800(v=vs.90).aspx

If you want to completely turn control over to a second page then you need to use Response.Redirect . If your business rules say you can't use this, then I'd suggest you revisit the business rules and change them.

Finally I found the solution. Thank you all for your help(+1 for everyone who gave me an idea).

So here was my code:

cs: Server.Transfer("~/Success.aspx",false);

HTML:

<div id="submit">                   
                    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" UseSubmitBehavior="False" />                   

</div>

As mentioned Submit button was inside an Update panel. In this case we need to use the following code :

 <Triggers>
       <asp:PostBackTrigger ControlID="btnSubmit" />
  </Triggers>

This code basically makes the execution of the submit button Synchronous(overrides the Update-panel Behavior).

Without seeing much of the code, it's hard to really debug this issue. Use the Response.Redirect function instead.

Response.Redirect("~/Success.aspx");

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