简体   繁体   English

Server.Transfer不起作用

[英]Server.Transfer does not work

After lots of research still I do not have an answer. 经过大量研究,我仍然没有答案。

I use WebForm app VS 2013. 我使用WebForm应用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. 此后,执行Success.aspx加载事件,但是在浏览器中,我只会看到原始的Main表单。

I created any empty Web Form with only a Button on it but after running the following code 我创建了一个仅带有按钮的空Web窗体,但是运行了以下代码之后

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

still I see MainForm.aspx,(Page_load event handler of WebForm2 runs) 我仍然看到MainForm.aspx,(运行WebForm2的Page_load事件处理程序)

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

Update per IrishGrifgin's comments. 根据IrishGrifgin的评论进行更新。

I indeed have aJax in my code. 我的代码中确实包含aJax。 I do have UpdatePanels which use Ajax.If this is the problem for server.Transfer how can we resolve this? 我确实有使用Ajax的UpdatePanels,如果这是服务器的问题,请问如何解决?

I don't think you understand what Server.Transfer() does. 我认为您不了解Server.Transfer()功能。

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. 浏览器很可能无法从第二页获取(或查看)html。

See https://msdn.microsoft.com/en-us/library/ms525800(v=vs.90).aspx 参见https://msdn.microsoft.com/zh-cn/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 . 如果要完全将控制权移至第二页,则需要使用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). 谢谢大家的帮助(给我一个主意的人+1)。

So here was my code: 所以这是我的代码:

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

HTML: 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). 这段代码基本上使提交按钮的执行同步(重写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函数。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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