简体   繁体   English

window.beforeunload提示不会隐藏Ajax更新进度

[英]window.beforeunload prompt does not hide the ajax update progress

I used the code capturing the 我使用了捕获

$(window).on('beforeunload unload', function (element) { 
  return 'Are you sure you want to leave?';
});

On the same page I have a update panel and a update progress. 在同一页面上,我有一个更新面板和一个更新进度。 If user navigates to other page by clicking on button the prompt message appears and the update progress also kick in. 如果用户通过单击按钮导航到其他页面,则会出现提示消息,并且更新进度也会开始。

If the user select no in the alert window and stays on the same page the update progress still stays on in visible state. 如果用户在警报窗口中选择“否”并停留在同一页面上,则更新进度仍保持可见状态。

Is there any way that I can capture the user's response to the "Changes may not be saved prompt" so based on the result I will hide the update progress image. 有什么方法可以捕获用户对“更改可能不会保存的提示”的响应,因此基于结果,我将隐藏更新进度图像。

 <asp:UpdatePanel runat="server" ID="ProductSelectorContainerPanel" UpdateMode="Conditional">
                <ContentTemplate>

 <asp:Button runat="server" ID="DoPartialPostBack" OnClick="DoPartialPostBack_Click" Text="Do Postback"/>

   </ContentTemplate>
 </asp:UpdatePanel>

.cs Code .cs代码

protected void DoPartialPostBack_Click(object sender, EventArgs e) { Response.Redirect("page2.aspx"); 受保护的void DoPartialPostBack_Click(object sender,EventArgs e){Response.Redirect(“ page2.aspx”); } }

Now if you add a debugger the Response redirect gets called in first. 现在,如果添加调试器,则会首先调用Response重定向。 Which will call the beforeunload code for the jquery. 它将调用jquery的beforeunload代码。 and based on the selected result(in my case stay) the update progress will fire as its a postback. 并根据选择的结果(以我的情况为准)更新进度将作为回发。

...so based on the result I will hide the update progress image ...所以根据结果,我将隐藏更新进度图像

Just hide it in the beforeunload handler. 只需将其隐藏在beforeunload处理程序中即可。 If the user leaves the page, it doesn't matter whether it's hidden; 如果用户离开该页面,则该页面是否被隐藏都没有关系。 they've left the page. 他们离开了页面。 If they don't, you have the result you want. 如果没有,您将获得想要的结果。

I changed code for adding a full postback trigger for the button. 我更改了为按钮添加完整的回发触发器的代码。 So the button does behavior like a normal button and button call is stopped when user selects the no in the alert. 因此,按钮的行为类似于普通按钮,并且当用户在警报中选择“否”时,按钮调用将停止。

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

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