为什么__LASTFOCUS隐藏字段仅显示在一些ASP.Net页面上? [英] Why does __LASTFOCUS hidden field show up on only some ASP.Net pages?
问题描述
我一直使用这篇文章中的hookonfocus方法:
http: //www.codeproject.com/KB/aspnet/MainatinFocusASPNET.aspx
在某些.aspx页面的回发期间保持焦点。不过,我注意到几个页面(和一个测试项目中的一些非常简单的页面)不包括隐藏字段__LASTFOCUS。我试图找出哪些选项,我错过了这将导致这个隐藏的领域出现,并用于恢复焦点,如果我使用JavaScript保持最新焦点更改发生在ASPX页面__LASTFOCUS。
注意:我使用的是VS 2005 / .Net 2.0。 __ LASTFOCUS
字段是由创建的。
- /msdn.microsoft.com/en-us/library/ms223392%28v=VS.80%29.aspxrel =nofollow> ClientScriptManager.GetPostBackEventReference(PostBackOptions,Boolean) if PostBackOptions.TrackFocus 已设置。
- Page.SetFocus
- BaseValidator.Validate()(via
Page.SetValidatorInvalidControlFocus
$ b它也被称为O CheckBox,ListControl和TextBox(以及任何派生类)的nPreRender方法。我猜测,不输出
__ LASTFOCUS
字段的页面不包含这三个控件的任何变体。I'd been using the hookonfocus method from this article: http://www.codeproject.com/KB/aspnet/MainatinFocusASPNET.aspx
to maintain focus during postbacks for certain .aspx pages. However, I've noticed that several pages (and some very simple pages in a test project) don't include the hidden field __LASTFOCUS. I'm trying to figure out which options I'm missing that will cause this hidden field to show up and be used to restore focus if I use javascript to keep __LASTFOCUS up to date when focus changes happen in an ASPX page.
Note: I'm using VS 2005/.Net 2.0 in case that makes a difference.
解决方案The
__LASTFOCUS
field is created byPage.RegisterFocusScript()
, which is called from...- ClientScriptManager.GetPostBackEventReference(PostBackOptions, Boolean) if PostBackOptions.TrackFocus is set.
- Page.SetFocus
- BaseValidator.Validate() (via
Page.SetValidatorInvalidControlFocus
) to focus controls that fails validation
It is also called in the OnPreRender method of CheckBox, ListControl and TextBox (and any derivatives). I'm guessing that the pages that does not output the
__LASTFOCUS
field does not contain any variant of these three controls.这篇关于为什么__LASTFOCUS隐藏字段仅显示在一些ASP.Net页面上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!