简体   繁体   English

如何禁用浏览器提示以确认ASPX页面中的页面刷新?

[英]How to disable browser prompt to confirm page refresh in an ASPX page?

I have an aspx page that is shown inside a windows application's (inside a WebBrowser control). 我有一个aspx页面,显示在Windows应用程序的内部(在WebBrowser控件内部)。 Under a certain condition, the windows application issues a reload on the WebBrowser and this results in the following prompt to be shown: 在特定条件下,Windows应用程序在WebBrowser上发出重新加载,这导致显示以下提示:

在此处输入图片说明

Now this page only shows a report and this prompt is completely out of place and is actually an irritant to the end user. 现在,此页面仅显示报告,并且此提示完全不合时宜,并且实际上对最终用户有刺激性。 I've tried changing the aspx form method to GET instead of POST as this prompt only seems to come for a page with form data, but that breaks the functionality of the page. 我尝试将aspx表单方法更改为GET而不是POST,因为此提示似乎只出现在具有表单数据的页面上,但这破坏了页面的功能。
I am at my wits end now with how to disable this prompt from being shown? 我现在不知所措,如何禁止显示此提示?
Is there an event I can capture that can help supress this message? 我可以捕获一个事件来帮助抑制此消息吗?

EDIT: A little more detail about the scenario: This aspx page I am working with has tabs and radio buttons as server side HTML controls. 编辑:有关方案的更多细节:我正在使用的此aspx页面具有选项卡和单选按钮作为服务器端HTML控件。 Their statuses are maintained through hidden fields embedded in the page. 通过嵌入在页面中的隐藏字段来维护其状态。 Once the values of the hidden fields are set and the aspnet form submitted, that's when the browser starts detecting any refresh as a resubmission and shows the dialogue. 一旦设置了隐藏字段的值并提交了aspnet表单,浏览器即会开始检测任何刷新作为重新提交并显示对话框。 I have gotten past the issue, details in my answer 我已经解决了这个问题,答案中有细节

This prompt is likely a side effect of the PRG pattern ( http://en.wikipedia.org/wiki/Post/Redirect/Get ) which is meant to avoid double posting of data. 此提示可能是PRG模式( http://en.wikipedia.org/wiki/Post/Redirect/Get )的副作用,其目的是避免重复发布数据。

You probably have a redirect on the URL you are trying to post to. 您可能对要发布到的URL进行了重定向。

In the browser debugger (use Firebug if you can, to to get maximum details), check the network requests and look for a 301/302/303 type requests. 在浏览器调试器中(如果可能,请使用Firebug以获得最大的详细信息),检查网络请求并查找301/302/303类型的请求。

Actually you do not won to change this functionality (I think maybe change on IE on options, but not on other browsers), but you need to change your way of making the report. 实际上,您不会赢得更改此功能的机会(我认为也许可以在IE的选项上进行更改,但不能在其他浏览器上进行更改),但是您需要更改制作报告的方式。

Instead of make the report after a button click and a post back, try to add the parameter in the url, read this parameter and make the report. 而不是在单击按钮并回发后创建报告,而是尝试在url中添加参数,阅读此参数并生成报告。

So no post back needed to be made, and nether reload with this messages need to be done. 因此,无需发回邮件,也无需重新加载此消息。

Here's how we solved the issue: 解决问题的方法如下:

As explained in my edit to the question, the change in values of the hidden fields and a subsequent form submit made the browser (rightly) flag that the page has already been submitted. 如我对问题的编辑中所述,隐藏字段的值更改和随后的表单提交使浏览器(正确地)标记为页面已提交。
We have now changed the form.submit() to a jQuery $.post() that looks like below: 现在,我们已将form.submit()更改为类似于以下内容的jQuery $ .post():

$.post(myForm.action, request, function(d) {
                        // Callback function that uses the returned response data d
                        // to extract the html and render the page again after completion
                        // of the Ajax request
                    });

request: Is the JSON object containing the key:value pairs that maintain state of the controls request:JSON对象是否包含维持控件状态的key:value对

Note: In the Page_Load() method of the aspx page, one needs to set the values of the hidden fields by reading them from the HttpContext's Request object 注意:在aspx页面的Page_Load()方法中,需要通过从HttpContext的Request对象读取隐藏字段的值来设置它们的值。

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

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