Prevent user's navigation to a different tab in Ajax toolkit's TabContainer control

Discussion in 'ASP' started by urstop, Nov 13, 2009.

  1. urstop

    urstop New Member

    Joined:
    Oct 17, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0

    Introduction



    Today I was working with the Tab Container control from Ajax tool kit and I had this requirement of preventing the user from navigating off to a different tab without completing the required fields on the active tab he was in. There is no direct feature in the toolkit that provides this feature. Googling around did not help me much. So, I sat down to write it. And here is code that I came up with that helps us to achive this feature. Not sure if this is the right way, but it does the job.

    Background



    Using Javascript to add functionality to the Ajax toolkit TabControl to prevent user from navigating off to a different tab.

    The code



    Add the below code to your page and call the necessary validation function at the place where I have called doYourValidations();. It should return true on success and false on a failure.

    Code:
    var ref_set_activeTab = null;
        var canChangeTab = false;
        function PanelClicked(sender, e)
        {
            var ctrl = sender.get_owner();
            if(ref_set_activeTab == null)
                ref_set_activeTab =  ctrl.set_activeTab;
            canChangeTab = doYourValidations();
            if(canChangeTab)
                ctrl.set_activeTab = ref_set_activeTab;
            else
                ctrl.set_activeTab = function(obj){};
            
        }
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
  3. technica

    technica New Member

    Joined:
    Dec 15, 2007
    Messages:
    107
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.technicaltalk.net
    Re: Prevent user's navigation to a different tab in Ajax toolkit's TabContainer contr

    Nice article to read.
     
  4. rasd123

    rasd123 Banned

    Joined:
    Nov 4, 2009
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    0
    Re: Prevent user's navigation to a different tab in Ajax toolkit's TabContainer contr

    Thanks for the info, I appreciate it.
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice