ASP.NET Cafe
Tips and Tricks

Focusing controls from serverside with and without AJAX Extensions

Wednesday, 9 April 2008 14: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.

Currently rated 3.0 by 1 people

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

Related posts

Comments

May 5. 2008 08:46

pingback

Pingback from dotnetumbria.org

ASP.NET Ajax - Tips & Links - Fabrizio Bernabei' Blog

dotnetumbria.org

Add comment


(Will show your Gravatar icon)  

  Country flag

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



Live preview

August 27. 2008 23:00