home *** CD-ROM | disk | FTP | other *** search
/ business-86-101-185-173.business.broadband.hu / business-86-101-185-173.business.broadband.hu.zip / business-86-101-185-173.business.broadband.hu / scs.zip / SetFocus.js < prev    next >
Text File  |  2010-03-31  |  2KB  |  46 lines

  1. var lastFocusedControlId;
  2.  
  3. /*
  4. * Handles page loaded event, finds first control on the page to set focus on and calles focus control on this control.
  5. * This handler assigned to handle Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded event on MasterPage
  6. */
  7. function pageLoadedHandler(sender, args) {
  8. // If you do not want focus set to the firsst element, comment out the next line.
  9.     setTimeout("setFocus()",1000);
  10. }
  11.  
  12. function setFocus() {
  13.     lastFocusedControlId = Fev_FocusOnFirstFocusableFormElement();   
  14.     if (lastFocusedControlId != null && typeof(lastFocusedControlId) !== "undefined" && lastFocusedControlId != "") {
  15.         var newFocused = $get(lastFocusedControlId);
  16.        if (newFocused) {
  17.             focusControl(newFocused);
  18.         }
  19.     }
  20. }
  21.  
  22. /*
  23. * Sets the focus to the target control.
  24. */
  25. function focusControl(targetControl) {
  26.     if (Sys.Browser.agent === Sys.Browser.InternetExplorer) {
  27.         var focusTarget = targetControl;
  28.         targetControl.focus();
  29.  
  30.         if (focusTarget && (typeof(focusTarget.contentEditable) !== "undefined")) {
  31.                oldContentEditableSetting = focusTarget.contentEditable;
  32.                focusTarget.contentEditable = false;
  33.             }
  34.            else {
  35.                focusTarget = null;
  36.             }  
  37.             if (focusTarget) {
  38.             focusTarget.contentEditable = oldContentEditableSetting;
  39.         }  
  40.     }
  41.     else {
  42.         targetControl.focus();
  43.     }
  44. }
  45.  
  46.