Solved

Set active Bootstrap Tab from VB Code Behind

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
performance issue in asp web 5 32
how i fix Remove render-blocking JavaScript 3 54
Increase the size of the modal in Bootstrap 5 27
Sort Order Icons on HTML Table 3 23
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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.
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

777 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