Click here to Skip to main content
15,884,353 members
Articles / Web Development / ASP.NET

Tabstrip Without Post back

Rate me:
Please Sign up or sign in to vote.
4.70/5 (18 votes)
2 Feb 2007CPOL2 min read 71.3K   841   63   20
An article to create tabstrip without post back

Tab Strip

Introduction

The article will help you in making a tabstrip control which can switch between tabs without a post back.

Background

It was couple of months before I got into the situation of implementing a tabstrip in my project and I started with the implementation of Microsoft's multi page control, but I found that it would be irritating for the user to post back the page for the purpose of switching between the tabstrips. So, I sat down and started writing my own code in JavaScript which will need no post back for the switching of tabs.

Using the Code

I have used two tables; one is for tabstrip head and another for the tab page. You can change the design as you wish. First, I will declare the tabstrip head and the tabstrip page so that the script can come to know the tabstrips used and initialize them accordingly. If you have more than one tabstrip for a page, then you can declare by comma separated as tabstrip head and tabstrip page respectively.

HTML
<script language="javascript" type="text/javascript">
    // declare the tabstrip at the top of the page
    // if more than one tabstrip then, 
    // tabstrips = "tabstrip1,tabstrip2"
    tabstrips = "EditRecordTab" 
    tabheads = "TabStrip_1" //tabheads="tabhead_1,tabhead_2"
</script>

Then, I am going to design the tabstrip head. I am using the hidden field to store the tab page index currently showing. This can be used either to:

  • Initialize the tabstrip specifying the page it has to show initially.
  • If you set that to empty, then no page will be shown by default.
  • It also maintains the state of the tab page if post back happens.
HTML
<table id="TabStrip_1" cellspacing="0" >
<tr >
<td align="Left" ><asp:LinkButton OnClientClick=
    "InitializeTabstrip('EditRecordTab',1, this); 
    return(false);" runat="server" ID ="FirstButtonCtl"  
    Font-Underline="false" > First <
    /asp:LinkButton></td>
<td align="Left" ><asp:LinkButton OnClientClick=
    "InitializeTabstrip('EditRecordTab',2, this); 
    return(false);" runat="server" ID ="SecondButtonCtl" 
    Font-Underline="false"> Second <
    /asp:LinkButton></td>
<td align="Left" ><asp:LinkButton OnClientClick=
    "InitializeTabstrip('EditRecordTab',3, this); 
    return(false);" runat="server" ID ="ThirdButtonCtl"   
    Font-Underline="false"> Third <
    /asp:LinkButton></td>
<td ><input type="hidden" id="EditRecordTabState" 
    runat="server" value="1" enableviewstate="true" /> 
    </td>
<td ></td>
</tr>
</table>

Below is the designing of the tab pages. I have added three user controls inside the div. You can add any control inside the div. The id of the control specified in the "div" and the InitializeTabstrip function should be the same.

HTML
<table width="100%">
    <tr>
    <td >
    <div id="EditRecordTab_1" visible="false"><
        usrctl:First   ID="FirstCtl" runat="server" /></div>
    <div id="EditRecordTab_2" visible="false"><
        usrctl:Second  ID="SecondCtl" runat="server"  /></div>
    <div id="EditRecordTab_3" visible="false"><
        usrctl:Third ID="ThirdCtl" runat="Server" /></div>
    </td>
    </tr>
    </table>

Don't forget to add the reference for the JavaScript file attached.

Please rate the article and don't hesitate to write to me in case you have any doubts or concerns.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Microsoft Corporation
India India
I work for Microsoft on MS technologies for application development. My interests include .net, WCF, Azure, Windows Phone, ASP.net, SL, WCF, WPF and many more.

You can visit my site at http://www.jebarson.info

Follow me on twitter @jebarson007

Comments and Discussions

 
GeneralCool Pin
keyur soni5-Feb-10 18:00
keyur soni5-Feb-10 18:00 
GeneralI have a problem with the tabstrip code... Pin
katski116-Nov-08 10:53
katski116-Nov-08 10:53 
GeneralRe: I have a problem with the tabstrip code... Pin
jebarson13-Nov-08 3:21
jebarson13-Nov-08 3:21 
GeneralRe: I have a problem with the tabstrip code... Pin
katski1119-Nov-08 4:11
katski1119-Nov-08 4:11 
GeneralFavor... Translate VB Code to C# Pin
katski1125-Sep-08 1:56
katski1125-Sep-08 1:56 
GeneralRe: Favor... Translate VB Code to C# Pin
jebarson29-Sep-08 6:19
jebarson29-Sep-08 6:19 
GeneralRe: Favor... Translate VB Code to C# Pin
katski112-Oct-08 7:15
katski112-Oct-08 7:15 
GeneralError while accessing page Pin
Sanspirit7-Apr-08 0:43
Sanspirit7-Apr-08 0:43 
AnswerRe: Error while accessing page Pin
jebarson9-Apr-08 9:41
jebarson9-Apr-08 9:41 
QuestionHow to make nested Tabstrips? Pin
Dane Weasel28-Nov-07 19:52
Dane Weasel28-Nov-07 19:52 
AnswerRe: How to make nested Tabstrips? Pin
jebarson29-Nov-07 3:33
jebarson29-Nov-07 3:33 
GeneralRe: How to make nested Tabstrips? [modified] Pin
Dane Weasel29-Nov-07 6:00
Dane Weasel29-Nov-07 6:00 
Thank you for quick response Smile | :)

Here[^] is a screen shot of what i have come up with.
It has some 'issues' i can not figure out, <whining>since my Java Scripting is not as good as i could wish</whining> Wink | ;)
The screen shot shows nested tabstrips, configured to open third tab, wich contain the nested tabstrip.

First - In the screen shot nothing has been clicked on yet, but the Third tab & FirstNest tab is not styled as the 'active' tabs ??
If you click a tab, it will get style as active tab from then on - e.g. it is only on pageload that the active tab styling is missing.
Second - Only one tab can be styled active - but the tab containing the nest, should stay styled active even when a tab in the nest is active...
Third - the nested tabstrip always display all tab <div>'s, until a tab in the nested tabstrip has been clicked... Solved!

A modified version (including my screen shot) of your example can be downloaded here.

--
Needing help is like needing a parachute! - If it aint there the first time you need it, chances are you will never need it again...

modified on Tuesday, December 04, 2007 6:15:30 AM

GeneralNice Pin
Sameh Saeed Mohammad17-Aug-07 22:46
professionalSameh Saeed Mohammad17-Aug-07 22:46 
AnswerRe: Nice Pin
jebarson18-Aug-07 21:39
jebarson18-Aug-07 21:39 
GeneralExcellent! Pin
RajLetsDoProgramming10-Jul-07 21:39
RajLetsDoProgramming10-Jul-07 21:39 
AnswerRe: Excellent! [modified] Pin
jebarson11-Jul-07 2:54
jebarson11-Jul-07 2:54 
GeneralCool! Pin
ryanoc3336-Feb-07 4:10
ryanoc3336-Feb-07 4:10 
GeneralRe: Cool! Pin
jebarson6-Feb-07 23:17
jebarson6-Feb-07 23:17 
GeneralRe: but Firefox exception... Pin
rghubert18-Feb-07 22:43
professionalrghubert18-Feb-07 22:43 
GeneralRe: but Firefox exception... Pin
jebarson19-Feb-07 4:26
jebarson19-Feb-07 4:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.