Open a custom tab on another page using ASP.NET Web Forms

I have a website and I am using Bootstrap. I have several links in the footer that will link to different tabs on different pages. My problem is that no matter which tab I provide the link to open, they only load the page by default.

I've done this several times with static sites, but never with ASP.NET. I believe the problem is that ASP.NET is adding .aspx to the end of every page.

Here's what I've tried:

<a href="/Personal-Banking.aspx#checking">Checking Accounts</a>

      

So, the page I'm linking to is Personal-Banking.aspx and the ID of the tab I want to open is #checking. All of this now opens the Personal-Banking page and opens the default tab, which is different from the #checking tab.

I tried to remove the .aspx but it still doesn't open correctly and all images are broken.

Thanks for the help.

+3


source to share


2 answers


Here is the code used to bind to tabs to work in asp.net webforms:



<!--Update this to reflect tabs on this page-->
    <script type="text/javascript">
        $(function () {
            var loc = window.location.href; // returns the full URL
            if (/pipe/.test(loc)) {
                $('.pipe').addClass('active');
                $('#pipe').addClass('active');
            }
            else if (/manholes/.test(loc)) {
                $('.manholes').addClass('active');
                $('#manholes').addClass('active');
            }
            else if (/fittings/.test(loc)) {
                $('.fittings').addClass('active');
                $('#fittings').addClass('active');
            }
            else if (/tanks/.test(loc)) {
                $('.tanks').addClass('active');
                $('#tanks').addClass('active');
            }
            else {
                $('.pipe').addClass('active');
                $('#pipe').addClass('active');
            }
        });
    </script>

      

+1


source


Inspect the page you are linking to, look at the source of the webpage in your browser when you get to it. Is ID

this tab valid "checking"

, or is it something like "MainContent_TabbedPanel_checking"

?



Don't look at your code, look at what your browser is doing.

+1


source







All Articles