Connecting Tech Pros Worldwide Forums | Help | Site Map

windows mobile how to set focus in textbox

Newbie
 
Join Date: Nov 2008
Posts: 22
#1: Jun 28 '09
Hi all
i am trying to set focus in textbox. Its a System.Web.UI page. and textbox is System.Web.UI.WebControls
so using setfocus works fine in desktop window but setfocus doesnt work in windows mobile.

any work around this problem.
i hope i have made my statement clear
i saw other thread too but that seems to be dead

Thanks

Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,270
#2: Jun 30 '09

re: windows mobile how to set focus in textbox


Web applications require that you use javascript to give a control focus.
You can use the document.getElementById(idstring) to grab the control you are after and then use .focus().
Stick that snipit in the javscript's load event for the body element.


Edit, I made this helper function you can use.
Expand|Select|Wrap|Line Numbers
  1. function focusById(idstring)
  2. {
  3.     var o=document.getElementById(idstring);
  4.     if(o!=undefined)
  5.     {
  6.         o.focus();
  7.     }
  8. }
  9.  
Newbie
 
Join Date: Nov 2008
Posts: 22
#3: Jul 2 '09

re: windows mobile how to set focus in textbox


thanks for your reply
i will try your solution and let you know if it works in mobile environment
Reply