简体   繁体   English

我可以使用javascript检测asp.net的事件吗?

[英]Can I use javascript to detect events of asp.net?

I am now trying to use gridview to create a web application for users to delete some rows from database. 我现在正在尝试使用gridview创建一个Web应用程序,以便用户从数据库中删除一些行。 However, whenever I refresh the whole page, strange things happen as selectedIndexChanged was called. 但是,每当刷新整个页面时,都会发生奇怪的事情,因为调用了selectedIndexChanged。 Is there any way that I can avoid this method being called whenever I refresh the table or is can I use javascript to detect this event? 有什么方法可以避免每次刷新表时都会调用此方法,还是可以使用JavaScript来检测此事件? If not, can I generate a yes no dialog for that event like javascript? 如果不是,是否可以为该事件(如javascript)生成是或否对话框? I am quite new to asp.net and my questions may be quite stupid. 我对asp.net相当陌生,我的问题可能很愚蠢。 Please help! 请帮忙!

I think you need to decide if you want to use JS or ASP to handle events on the page. 我认为您需要确定是否要使用JS或ASP处理页面上的事件。

If you want to use JS, then disable server processing in your ASP tags and handle all the interactions with JS in your page and only process at the server on page submit. 如果要使用JS,则在ASP标记中禁用服务器处理,并处理页面中与JS的所有交互,并且仅在页面提交时在服务器上进行处理。 ASP can generate the grid for you on page load, but then let JS handle the client side interactions. ASP可以在页面加载时为您生成网格,但随后让JS处理客户端交互。

If you want to use ASP, then set your grid to process on the server (runat="server") and forget about JS. 如果要使用ASP,则将网格设置为在服务器(runat =“ server”)上处理,而不必考虑JS。

Well seems I found out the solution. 好吧,我似乎找到了解决方案。 Actually C# also provides yes no dialog. 实际上,C#还提供“是,否”对话框。 Seems I could use it to manually stop that event but it seems that I cannot avoid selectedIndexChanged being called when refreshing the page. 似乎我可以使用它来手动停止该事件,但是似乎无法避免刷新页面时调用selectedIndexChanged。 Thank you every one for your help. 感谢大家的帮助。

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

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