Manually go to next control when Tab is pressed

Last post 05-12-2008 8:56 AM by msnyder0. 3 replies.

Sort Posts:

  • Manually go to next control when Tab is pressed

    05-12-2008, 7:47 AM
    • Member
      491 point Member
    • msnyder0
    • Member since 06-29-2007, 2:04 PM
    • PA, USA
    • Posts 226

    I'm using a custom AJAX control that's being created dynamically in a GridView. These controls call JavaScript functions when they're clicked. At the end of the JavaScript function, I'd like to include some code to automatically focus on the next one of these controls on the page if the Tab key was pressed. Right now, the Tab key always selects the address bar when tabbing off of this custom control.

    As always, any help is greatly appreciated. Thanks!

  • Re: Manually go to next control when Tab is pressed

    05-12-2008, 7:53 AM

    This behaviour is controlled client-side by use of the TabIndex attribute, which is exposed as a server-side property in ASP.NET controls.

    http://msdn.microsoft.com/en-us/library/ms178231.aspx 

     

    Regards Mike
    [MVP - ASP/ASP.NET]
    My site    Please help - URGENT!!!    What ASP.NET can and can't do
  • Re: Manually go to next control when Tab is pressed

    05-12-2008, 8:07 AM
    • Member
      491 point Member
    • msnyder0
    • Member since 06-29-2007, 2:04 PM
    • PA, USA
    • Posts 226

    Ya, I don't think it's working for some reason, possibly because of how the custom control works. The TabIndex is set to its default, 0, right now (I tried setting it equal to other values with no luck). I also tried looping through the GridView and setting the TabIndex to an incrementing counter. No luck with that either. :-(

  • Re: Manually go to next control when Tab is pressed

    05-12-2008, 8:56 AM
    • Member
      491 point Member
    • msnyder0
    • Member since 06-29-2007, 2:04 PM
    • PA, USA
    • Posts 226

    Alright, I have some new information as to why the TabIndex may not be working... When I throw this bit in at the end of the JavaScript function (hard-coded control name for testing)...

       document.getElementById('ctl00$ContentPlaceHolder1$gvList$ctl02$ieData_vcComment_080414C01BagL1').focus();

    I get a JavaScript error that says "Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept focus."
    I tried putting these two lines above the .focus() line above with no luck...

       document.getElementById('ctl00$ContentPlaceHolder1$gvList$ctl02$ieData_vcComment_080414C01BagL1').enabled = true;
       document.getElementById(
    'ctl00$ContentPlaceHolder1$gvList$ctl02$ieData_vcComment_080414C01BagL1').visible = true;

    Is there a way to get this working?

Page 1 of 1 (4 items)