SetFocus

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());
}
 
J

José Araujo

I resolved this. I wrote my own server control that just renders script
code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top