J
José Araujo
Hi,
I am trying to set my MobileApp to set the focus to a given component.
For regular webforms it seems that the classic solution is to use the code
below, which in turn inserts JavaScript code in the page that does the job.
I am trying to use the same in my page, but it doesn't work. It doesn't
insert any code in the resulting HTML page (when you use view source in IE).
Any ideas? Thanks, José Araujo.
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());
}
I am trying to set my MobileApp to set the focus to a given component.
For regular webforms it seems that the classic solution is to use the code
below, which in turn inserts JavaScript code in the page that does the job.
I am trying to use the same in my page, but it doesn't work. It doesn't
insert any code in the resulting HTML page (when you use view source in IE).
Any ideas? Thanks, José Araujo.
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());
}