Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set initial control focus in web forms
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
00853352
Message ID:
00853448
Views:
15
Shouldn't the base Mere Mortals webpage be enhanced to emit this javascript automatically? Then everyone could benefit.

>In case anyone might need it here is a C# version of the code found here: http://www.dotnetbips.com/displayarticle.aspx?id=106
>It allows you to set the intial focus of a web page to a specific control.
>
>  private void SetInitialFocus(Control ctrl)
>  {
>   StringBuilder s = new StringBuilder();
>   s.Append("<SCRIPT LANGUAGE='JavaScript'>");
>   s.Append("function SetInitialFocus()");
>   s.Append("{");
>   s.Append("   document.");
>
>   Control p  = ctrl.Parent;
>   while (p.GetType() != typeof(HtmlForm))
>    p = p.Parent;
>   s.Append(p.ClientID);
>   s.Append("['");
>   s.Append(ctrl.UniqueID);
>   s.Append("'].focus();");
>   s.Append("}");
>   s.Append("window.onload = SetInitialFocus;");
>   s.Append("</SCRIPT>");
>   ctrl.Page.RegisterClientScriptBlock("InitialFocus", s.ToString());
>  }
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform