Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Setting focus to a control, browser independence?
Message
From
13/11/2003 10:00:10
 
 
To
All
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Setting focus to a control, browser independence?
Miscellaneous
Thread ID:
00849502
Message ID:
00849502
Views:
61
Hi mm.netters,

In an attempt to make my web forms more user friendly, I added the following method to my base form so that I can set focus to any control:
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.

Regards to all,
Neil
Next
Reply
Map
View

Click here to load this message in the networking platform