Why does __LASTFOCUS hidden field show up on only some ASP.Net pages?

折月煮酒 提交于 2019-12-25 03:39:11

问题


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.


回答1:


The __LASTFOCUS field is created by Page.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.



来源:https://stackoverflow.com/questions/6684181/why-does-lastfocus-hidden-field-show-up-on-only-some-asp-net-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!