问题描述
场景:我onbeforeunload里面我是用从当前页面(ASP.NET应用程序)导航离开之前显示信息的.aspx页面上的功能。这个网页是相当复杂的,其中后背上是在好几次例如发生我有多个按钮,拉德电网,拉德窗口弹出式广告等。
Scenario: I have onbeforeunload function on .aspx page which I am using to display a message before navigating away from current page (ASP.NET Application). This page is quite complex where post backs are happening at quite a few times e.g. I have multiple buttons, Rad Grid, Rad Window PopUps etc.
所以,所有的按钮调用onbeforeunload时,他们被点击和消息框被称为未必然。以prevent onbeforeunload消息,显示我只是呼吁按钮的事件的OnClientClick那里我打电话是空的另一个cancelEvent功能。通过这样做,所有的按钮后背上被处理,但我现在用的是radgrid控件具有按钮栏(删除)和一个只要行被从电网删除了offcourse刷新,最终调用onbeforeunload电网。
So, all the buttons call onbeforeunload whenever they are clicked and message box is being called un-necessarily. To prevent onbeforeunload message displaying I am just calling another cancelEvent function on button's OnClientClick event where I am just calling null. By doing this all the button post backs are handled but the RadGrid which I am using has Button Columns (Delete) and whenever a row is deleted from the grid it offcourse refreshes the grid which ultimately calls onbeforeunload.
请能谁能告诉我我该怎么prevent onbeforeunload当我从radgrid控件删除任何东西。以下是code片段,我使用和按钮,工作正常,但我需要帮助电网删除列可能是这样的,我可以用它来打电话给我cancelEvent按钮的事件的OnClientClick某些事件。
Could please anyone tell me how I can prevent onbeforeunload when I delete anything from RadGrid. Following is the code snippet that I am using and working fine for buttons but I need help for grid delete column may be some event like Button's OnClientClick event that I can use to call my cancelEvent.
window.onbeforeunload = confirmExit;
function confirmExit() {
window.event.returnValue = 'If you navigate away from this page any unsaved changes will be lost!';
}
function cancelEvent(event) {
window[event] = function () {null}
}
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" CssClass="ActionButtons"
ValidationGroup="vsDataEntry" OnClientClick="return cancelEvent('onbeforeunload')"/>
问候
推荐答案
试着做类似下面的
<div onclick="return cancelEvent('onbeforeunload')">
<telerik:RadGrid runat="server">
</telerik:RadGrid>
</div>
说明
在触发click事件它是通过DOM所有元素起泡。我们包裹radgrid控件的div内,只要任意点击碰巧DIV中我们删除的onbeforeunload。
When the click event is triggered it is bubbled through all the element in DOM. We are wrapping the Radgrid inside a div and whenever any click happens inside that div we are removing the onbeforeunload.
这篇关于如何停止在ASP.NET射击onbeforeunload功能上radgrid控件回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!