private void SetFocus(Control FocusControl) { System.Text.StringBuilder Script = new System.Text.StringBuilder(); string ClientID = FocusControl.ClientID; Script.Append("<script language='javascript'>"); Script.Append("document.getElementById('"); Script.Append(ClientID); Script.Append("').focus();"); Script.Append("</script>"); this.RegisterStartupScript("SetFocus", Script.ToString()); }Now I can set focus to any control on my web form by placing the following code in any event.
this.SetFocus(myControl)
I would appreciate those of you who have experience with browsers other that IE to comment on the impact this code will have if included in my base form. I also would like to know if anyone knows how to position the cursor of a textbox control at a specific spot in the text string after the textbox receives focus.