简体   繁体   English

使用ASP.NET Webforms在另一页上打开特定选项卡

[英]Open specific tab on another page with ASP.NET Webforms

I have a webforms website and I am using Bootstrap. 我有一个webforms网站,我正在使用Bootstrap。 I have a few links in my footer that will link to various tabs on different pages. 我的页脚中有一些链接会链接到不同页面上的各个标签。 My problem is that no matter what tab I specify the link to open, they only load the page with the default tab. 我的问题是,无论在哪个选项卡中指定要打开的链接,它们只会使用默认选项卡加载页面。

I've done this several times with static sites, but never with ASP.NET. 我已经使用静态站点多次完成此操作,但从未使用ASP.NET。 I believe the problem lies with ASP.NET adding the .aspx to the end of each page. 我相信问题在于ASP.NET将.aspx添加到每个页面的末尾。

Here is what I 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'm wanting to open is #checking. 所以,我链接到的页面是Personal-Banking.aspx,而我想要打开的标签的ID是#checking。 All this is doing now is opening the Personal-Banking page and opening the default tab, which is different than the #checking tab. 现在所做的就是打开个人银行页面并打开默认选项卡,该选项卡与#checking选项卡不同。

I've tried removing the .aspx but it still does not open correctly and the images are all broken. 我已经尝试删除.aspx但它仍然无法正确打开并且图像都被破坏了。

Thanks for the help. 谢谢您的帮助。

Inspect the page that you link to, look at the source of the webpage on your browser when you get to it. 检查您链接到的页面,查看浏览器上的网页来源。 Is the ID of that tab really "checking" , or is it something else like "MainContent_TabbedPanel_checking" ? 该选项卡的ID是否真的"checking" ,还是像"MainContent_TabbedPanel_checking"

Don't look at your code, look at what your browser is getting. 不要查看您的代码,看看您的浏览器获得了什么。

Here is the code used to get linking to tabs to work in asp.net webforms: 以下是用于链接到标签以在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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM