ASP.NET Cafe
new tricks every week

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:

[code=C#]Page.SetFocus(top.ClientID);[/code]

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.

[code=C#]ScriptManager.GetCurrent(Page).SetFocus(top);[/code]

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 (0) | Comment RSSRSS comment feed

Comments

Add comment


 

  Country flag

biuquote
  • Comment
  • Preview
Loading