[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

José Araujo

10/4/2005 11:13:00 PM

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


1 Answer

José Araujo

10/7/2005 8:26:00 PM

0

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

"José Araujo" <josea@mrcinc.com> wrote in message
news:O24EkkTyFHA.908@tk2msftngp13.phx.gbl...
> 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());
> }
>
>