在ASP.NET中保留页面之前保存数据

时间:2016-06-08 11:00:06

标签: javascript c# jquery asp.net webforms

我有asp.net页面。 我没有“保存”按钮(不是我的要求)。

我需要在离开此页面之前保存页面数据。

我试图用Page_Unload之类的事件做这件事,但它不起作用...... 原因Save方法使用来自页面上的元素的数据,如txtBox1.Text我无法使用.ashx处理程序进行一些ajax保存(或者我不知道如何使用页面处理程序中的元素,因为它们是protected)。

除了实现表单并将其传递给处理程序之外,还有其他解决方案吗?

1 个答案:

答案 0 :(得分:1)

您可以使用x=[1.234,0.000000,2.0,0.0001] for i in x: print(isinstance(i, int)) 事件。 它应该在卸载前开火。 它允许您回询用户是否真的要离开。检查simillar示例here

onbeforeunload

作为回报,您可以保存所需的值。

或者,您可以在用户离开时发送<script language="JavaScript"> window.onbeforeunload = confirmExit; function confirmExit() { return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?"; } </script> 请求。

相关问题