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
Solved

Set active Bootstrap Tab from VB Code Behind

Posted on 2015-01-17
4
1,247 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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

856 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