Public Sub mySetFocus(ByVal sPage As Page, ByVal ctrl As String) Dim f As StringBuilder = New StringBuilder() f.Append("<script language='JavaScript'>") f.Append("function setFocus() {") f.Append("document.getElementById('") f.Append(ctrl) f.Append("').focus();}") f.Append(" window.onload=setFocus;") f.Append("</") f.Append("script>") sPage.ClientScript.RegisterClientScriptBlock(sPage.GetType(), "<Focus>", f.ToString()) End Sub