ASP.NET Cafe
is better in 2009

Focusing controls from serverside with and without AJAX Extensions

Wednesday, 9 April 2008 09:03 by dmitriy

There is a thing that allows you to point user on the right place on page after postback. The secret is not a secret - just javascript focus() function called. But how to make this right using the ASP.NET framework. It's not a big deal... there are a function for this:

Page.SetFocus(top.ClientID);

And this works good in case of PostBack. But what going on if you are using partial postback ( using update panel of Ajax extensions )?
This does not work any more. But works this.

ScriptManager.GetCurrent(Page).SetFocus(top);

What also can you find useful ? Hmm...  sometimes it does not work. Why? 90% that are you trying to set focus on the Control that does not receive focus in browser.
Don't try to focus a Label. Focus Anchor tag if you need to focus a place on your page.

Usually peoples try to include javascript functions that do this job, but I think that this way is better.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   ASP.NET
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (1) | Comment RSSRSS comment feed

Comments

March 21. 2009 22:17

trackback

Trackback from DotNetKicks.com

Focusing controls from serverside with and without AJAX Extensions

DotNetKicks.com

Add comment


 

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Preview

July 3. 2009 18:37