[英]How do you call OnPageIndexChanging from Javascript?
I have code that when a user wants to page through a GridView, it asks them (using a JavaScript confirm) if they want to save the data from the grid. 我有一段代码,当用户想翻页GridView时,它询问他们(使用JavaScript确认)是否要保存网格中的数据。 So, I'm able to get the confirm to work (with the code-behind saving function), but I'm noticing that it's not firing the OnPageIndexChanging method - which basically defeats the purpose here.
因此,我能够(通过代码隐藏保存功能)使确认工作,但是我注意到它没有触发OnPageIndexChanging方法-这基本上违背了这里的目的。
So, to summarize, can JavaScript access the OnPageIndexChanging method? 因此,总而言之,JavaScript可以访问OnPageIndexChanging方法吗?
Thanks a lot 非常感谢
The OnPageIndexChanging
event is a server-side event, so it's not surprising that your Javascript handler isn't getting triggered. OnPageIndexChanging
事件是服务器端事件,因此没有触发Javascript处理程序也就不足为奇了。
I'm not sure if ASP.Net has a "built in" way to do this; 我不确定ASP.Net是否具有“内置”方式来执行此操作。 but you can do it by attaching your own Javascript listeners.
但是您可以通过附加自己的Javascript侦听器来实现。 Here is the general approach (I'm using JQuery to make it easier):
这是一般方法(我正在使用JQuery使其变得更容易):
click
listener for each of those links click
监听器 So, the code would look something like this: 因此,代码如下所示:
$("#grid a").each(function () {
$(this).click(function () {
return confirm("really?");
});
});
Notes 笔记
grid
is the ID of the GridView
control, so #grid a
selects every a
tag within my grid. grid
是的ID GridView
控件,所以#grid a
每选择a
标签我的网格内。 return confirm()
returns false if the user does not confirm, which effectively cancels the click event. return confirm()
返回false ,这将有效地取消click事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.