PsychoDazey
asked on
Setting focus to control
I am new to web forms (and C# for that matter)..I am trying to use this code I found on the web courtesy of Ryan Farley, that sets the focuse to a sepcified control. I am getting the following error:
The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)
Help?
public static void SetFocus(Control control)
{
StringBuilder sb = new StringBuilder();
sb.Append("\r\n<script language='JavaScript'>\r\n ");
sb.Append("<!--\r\n");
sb.Append("function SetFocus()\r\n");
sb.Append("{\r\n");
sb.Append("\tdocument.");
Control p = control.Parent;
while (!(p is System.Web.UI.HtmlControls .HtmlForm) ) p = p.Parent;
sb.Append(p.ClientID);
sb.Append("['");
sb.Append(control.UniqueID );
sb.Append("'].focus();\r\n ");
sb.Append("}\r\n");
sb.Append("window.onload = SetFocus;\r\n");
sb.Append("// -->\r\n");
sb.Append("</script>");
control.Page.RegisterClien tScriptBlo ck("SetFoc us", sb.ToString());
}
The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)
Help?
public static void SetFocus(Control control)
{
StringBuilder sb = new StringBuilder();
sb.Append("\r\n<script language='JavaScript'>\r\n
sb.Append("<!--\r\n");
sb.Append("function SetFocus()\r\n");
sb.Append("{\r\n");
sb.Append("\tdocument.");
Control p = control.Parent;
while (!(p is System.Web.UI.HtmlControls
sb.Append(p.ClientID);
sb.Append("['");
sb.Append(control.UniqueID
sb.Append("'].focus();\r\n
sb.Append("}\r\n");
sb.Append("window.onload = SetFocus;\r\n");
sb.Append("// -->\r\n");
sb.Append("</script>");
control.Page.RegisterClien
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
System.Text.StringBuilder sb = new System.Text.StringBuilder( );
ASKER
Thanks Vin, I awarded you the points. do you know what I would have to add to using for pageutility?
Good luck
VINHNL