Tips from Scott Guthrie himself
Wow.
This is the cleanest solution to one of ASP.NET most common problems, setting focus:
Scott Guthrie notes in his Blackbelt WebForms presentation:[Richard Caetano]
Sub SetFocus(ByVal controlToFocus As Control)
Dim scriptFunction As New StringBuilder
Dim scriptClientId As String
scriptClientId = controlToFocus.ClientID
scriptFunction.Append("<script language='javascript'>")
scriptFunction.Append("document.getElementById('")
scriptFunction.Append(scriptClientId)
scriptFunction.Append("').focus();")
scriptFunction.Append("</script>")
RegisterStartupScript("focus", scriptFunction.ToString())
End Sub
The sample is from Scott's new set of slides here.
Richard beat me to it :), Very clean.[ScottW]
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?!".