ASP.NET Hosting

Tips from Scott Guthrie himself


This is the cleanest solution to one of ASP.NET most common problems, setting focus:

Scott Guthrie notes in his
Blackbelt WebForms presentation:

Sub SetFocus(ByVal controlToFocus As Control)

Dim scriptFunction As New StringBuilder
Dim scriptClientId As String

scriptClientId = controlToFocus.ClientID

scriptFunction.Append("<script language='javascript'>")

RegisterStartupScript("focus", scriptFunction.ToString())

End Sub
[Richard Caetano]

The sample is from Scott's new set of slides here.

Richard beat me to it :), Very clean.


A must read. See ScottGu's post.
The goodness even starts on the first slide: the ~ feature is one of those were you get a shock asking you "how come i did not know this?!".


  • The shock is that it's not plastered in every ASP.Net demo page on MSDN. Simple things like this are great, but only if you know about them. '~' should have been somewhere prominent in the ASP.Net docs.

  • Ok, but when I try to do it using Atlas.NETit doesn't work. I'm using ASP.Net 2.0 and Atlas, but look, just doesn't work with IE, if you use Firefox the native function Focus() works very well.

    Can you help me?? - I thing a lot of people have the same issue.

    Thanks a lot,

    São Paulo / Brazil

  • .setfocus() solution


    That's the solution

    São Paulo / Brazil

Comments have been disabled for this content.