Solved

Set active Bootstrap Tab from VB Code Behind

Posted on 2015-01-17
4
1,494 Views
Last Modified: 2016-08-23
I'm using a Bootstrap NAV panel with NAV panes and I have a 2 part question:

1. How can I set the active tab-pane from VB code behind?

2. When my page loads, I see the 3 tabs and the 1st tab is active, but the contents of the tab are not seen until I click on the 2nd or 3rd tab??

Code is attached:
 <link href="Content/bootstrap.css" rel="stylesheet" />
    <script src="Scripts/jquery-2.1.3.js"></script>
    <script src="Scripts/bootstrap.js"></script>

    <div class="container">
        <div class="panel panel-info">
            <div class="panel-heading">
                <ul class="nav nav-tabs">
                    <li class="nav active"><a href="#A" data-toggle="tab">Tab A</a></li>
                    <li class="nav"><a href="#B" data-toggle="tab">Tab B</a></li>
                    <li class="nav"><a href="#C" data-toggle="tab">Tab C</a></li>
                </ul>
            </div>
            <div class="panel-body">
                <!-- Tab panes -->
                <div class="tab-content">
                    <div class="tab-pane fade" id="A">Content inside tab A</div>
                    <div class="tab-pane fade" id="B">Content inside tab B</div>
                    <div class="tab-pane fade" id="C">Content inside tab C</div>
                </div>
            </div>
            </div>
    </div>

Open in new window

0
Comment
Question by:BrianFord
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40557823
What type of web site are you using?  The Bootstrap navbar is not an ASP.NET component, per se, but you could make one that has server-side properties, and could generate the HTML that you need.
0
 

Accepted Solution

by:
BrianFord earned 0 total points
ID: 40558792
It's a fairly standard website using ASPX pages, I use the bootstrap css for a standard look & feel and the nav-tabs works perfectly for me.

I did actually manage to find a pretty simple solution which I've copied here for anyone else looking to do the same thing.

  Dim SB As New StringBuilder
        SB.Append("$(document).ready(function(){ ")
        SB.Append("$('#myTab li:eq(" & tabNum & ") a').tab('show');")
        SB.Append("});")

        ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ShowCollapse", SB.ToString, True)

Open in new window

0
 

Author Closing Comment

by:BrianFord
ID: 40567987
Self-solved
0
 

Expert Comment

by:Sherry Jackson
ID: 41767219
Hello, I'm looking to do the same but I don't quite follow your solution.  Would you mind sharing all of the ASPX and the code behind?
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question