Connecting Tech Pros Worldwide Help | Site Map

windows mobile how to set focus in textbox

  #1  
Old June 28th, 2009, 12:10 PM
Newbie
 
Join Date: Nov 2008
Posts: 21
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
  #2  
Old June 30th, 2009, 04:29 PM
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,096
Provided Answers: 3

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.  
  #3  
Old July 2nd, 2009, 10:56 AM
Newbie
 
Join Date: Nov 2008
Posts: 21

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