HighTechTalks DotNet Forums  

SetFocus

ASP.net Mobile microsoft.public.dotnet.framework.aspnet.mobile


Discuss SetFocus in the ASP.net Mobile forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
José Araujo
 
Posts: n/a

Default SetFocus - 10-04-2005 , 07:12 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());
}



Reply With Quote
  #2  
Old   
José Araujo
 
Posts: n/a

Default Re: SetFocus - 10-07-2005 , 04:25 PM






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

"José Araujo" <josea (AT) mrcinc (DOT) com> wrote

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





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.