Set focus to web control

G

Guest

Does anybody know how to set focus to a web control after a page postback? Can this be done? Thanks.
 
M

MSNews

If you are using IE 5.5 and above this can be easily achieved by setting the
smartNavigation attribute to "true". This attribute is set at the page
directive.

In case you are using any other browsers you should track the control that
initiates the postback and put focus on the same item when the page is
rendered in the client side again after the post back. You can get the name
of the control from the "__EVENTTARGET" form variable. This method is not
fool-proof. So you can overcome the problems in this method by following
this method.
1. Have a global variable in the page that is going to track the control
which has posted back.
2. As the control has posted back, it will get into its eventhandler.
3. In the event handler, set this globalVariable to the name of the current
control.
4. In the Pre-render of the page, registerClientscript to put focus on the
item name that is there in the global variable.

Hope this should help.


Karen said:
Does anybody know how to set focus to a web control after a page postback?
Can this be done? Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top