Link to home
Start Free TrialLog in
Avatar of PsychoDazey
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.RegisterClientScriptBlock("SetFocus", sb.ToString());
            }
Avatar of vinhnl
vinhnl

You must "using System.Text;"

Good luck
VINHNL
ASKER CERTIFIED SOLUTION
Avatar of vinhnl
vinhnl

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
System.Text.StringBuilder sb = new System.Text.StringBuilder();
Avatar of PsychoDazey

ASKER

Thanks Vin, I awarded you the points.  do you know what I would have to add to using for pageutility?