c# - Maintain Control focus across post backs using PostBackOptions.TrackFocus -


maintaining focus across post backs apparently difficult task. searching google, find ton of people desire same thing, hook differently, , mostly, custom-ly. avoid custom implementation, if there's way it's supported .net. after deep searching, did come across postbackoptions.trackfocus, mentioned quietly in stack overflow post. according msdn:

gets or sets value indicating whether postback event should return page current scroll position , return focus current control."

holy crap, supported .net 4? awesome. have ton of custom controls, how .net know how set focus on control? have no idea. looking msdn documentation system.web.ui.control, there's interesting method:

public virtual void focus() 

"use focus method set initial focus of web page control. page opened in browser control selected."

alright, overridable. recommended method of doing so? returns void. no examples. unable find examples of people overriding method in implementations. however, after overriding , doing nothing more throwing exception, becomes evident not how asp.net gets focus on control had focus before post back: never gets called.

after ton of debugging using firebug, have found enabling postbackoptions.trackfocus works! sometimes. apparent focus of control maintained when control calls __dopostback javascript method. other controls launch postback (when pressing enter inside control), call webform_onsubmit(), doesn't update asp hidden field __lastfocus. __dopostback calls webform_onsubmit() after setting hidden fields.

this i'm stuck. it's looks if need call __dopostback, no matter what. there's very, little documentation on use of trackfocus. have tips here?

i've been maintaining focus accross postbacks using method in article: (ie: store focus in __lastfocus hidden field on field enter event clientside controls)

http://www.codeproject.com/kb/aspnet/mainatinfocusaspnet.aspx

if you've gotten far having __lastfocus show on page, should of rest of way...

note: it'd nice find way keep javascript bloating __viewstate example.

it working pretty me until figured out of pages included hidden __lastfocus field , of pages didn't. (that's prompted me search around , find question) i'm trying figure out how make sure __lastfocus shows on every page want keep track of focus on... (looks i'll have open separate question it)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -