在C#中检测聚焦控制
发布时间:2020-12-15 21:29:51 所属栏目:百科 来源:网络整理
导读:我有一个更新面板,它在页面的一部分上引起回发,并且在回发之后,具有焦点的控件(不在更新面板中)失去焦点.如何识别哪个控件具有焦点并保存该值,以便在页面重新加载时可以重新聚焦它.谢谢. 解决方法 首先,我将焦点绑定在所有输入上并保留最后一个焦点控件ID.然
我有一个更新面板,它在页面的一部分上引起回发,并且在回发之后,具有焦点的控件(不在更新面板中)失去焦点.如何识别哪个控件具有焦点并保存该值,以便在页面重新加载时可以重新聚焦它.谢谢.
解决方法
首先,我将焦点绑定在所有输入上并保留最后一个焦点控件ID.然后在UpdatePanel完成加载后,我将焦点设置为最后一个
// keep here the last focused id var LastFocusedID = null; function watchTheFocus() { // on every input that get the focus,I grab the id and save it to global var $(":input").focus(function () { LastFocusedID = this.id; }); } var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_initializeRequest(InitializeRequest); prm.add_endRequest(EndRequest); function InitializeRequest(sender,args) { } // after the updatePanel ends I re-bind the focus,and set the focus // to the last one control function EndRequest(sender,args) { if(LastFocusedID != null) $('#' + LastFocusedID).focus(); watchTheFocus(); } jQuery(document).ready(function() { watchTheFocus(); }); 唯一的想法是我使用jQuery来制作它,但我在这里提出我的想法,你可以用更多的代码用jQuery来实现它. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |