Hi,
 
  public static void SetFocus(Page page, string controlID)
  {
 
   string javascript = string.Format( @"<script language=""javascript"">var 
called = false;
   if(document.body.onfocus)
   orig_document_body_onfocus = document.body.onfocus;
   document.body.onfocus = document_body_onfocus;
   function setFocus()
   {{
   var control = document.getElementById(""{0}"");
   if(control)
    control.focus();
   }}
   function orig_document_body_onfocus(){{}}
   function document_body_onfocus ()
   {{
   if( !called )
   {{
    called = true;
    setFocus();
   }}
   orig_document_body_onfocus();
   }}
   if( window.__smartNav && window.__smartNav.restoreFocus)
   {{
   orig_window__smartNav_restoreFocus = window.__smartNav.restoreFocus;
   window.__smartNav.restoreFocus = window__smartNav_restoreFocus;
   }}
   function orig_window__smartNav_restoreFocus(){{}}
   function window__smartNav_restoreFocus()
   {{
   setFocus();
   orig_window__smartNav_restoreFocus
   }}
   </script>", controlID);
   page.RegisterStartupScript("focus", javascript);
  }

  How to use this function:
  Suppose I have a button named cmdSave and a TextBox named "txtUseName". Now 
if I want to set focus on any of this control using above   function. 
  SetFocus(this,"txtUseName");
  SetFocus(this,"cmdSave");
 
Regards
Krishan Kant
 
 


Ali Husain <[EMAIL PROTECTED]> wrote:Hi guys... anyone know of an easy way to 
set the focus off a particular
button on the page.... For some reason one of my pages that has 2
buttons, it happens to be the logout button that gets focus so when the
user hits ENTER on their keyboard it logs them out instead of
submitting.



[Non-text portions of this message have been removed]



---------------------------------
YAHOO! GROUPS LINKS 


    Visit your group "AspNetAnyQuestionIsOk" on the web.
  
    To unsubscribe from this group, send an email to:
 [EMAIL PROTECTED]
  
    Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 


---------------------------------





--------------------------------------------------------------------
Krishan Kant Chamoli                 Office:    +91-172-2653886
AuthorGen Technology (P) Ltd.,       Fax:       +91-172-5018485
24/3, Industrial Area, Phase - 2,    Mobile: 9888263726
Chandigarh. INDIA. Pin - 160002.     Email: [EMAIL PROTECTED]

--------------------------------------------------------------------
Send instant messages to your online friends http://uk.messenger.yahoo.com 

[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to