Solved

Set active Bootstrap Tab from VB Code Behind

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Server Error 11 48
Change text to radio button and calendar form 2 36
Angular - "nest" service calls? 18 26
.NET tools for adding thread safety to a web app? 3 19
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
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)

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now