Click here to Skip to main content
Licence 
First Posted 2 Feb 2007
Views 44,305
Downloads 579
Bookmarked 60 times

Tabstrip without post back

By | 2 Feb 2007 | Article
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.

<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 gonna design the 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.
<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

    
<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 me in case you have any doubts or concerns.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

jebarson

Software Developer (Senior)
Microsoft Corporation
India India

Member

Follow on Twitter Follow on Twitter
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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralCool Pinmemberkeyur soni18:00 5 Feb '10  
GeneralI have a problem with the tabstrip code... Pinmemberkatski1110:53 6 Nov '08  
GeneralRe: I have a problem with the tabstrip code... Pinmemberjebarson3:21 13 Nov '08  
GeneralRe: I have a problem with the tabstrip code... Pinmemberkatski114:11 19 Nov '08  
GeneralFavor... Translate VB Code to C# Pinmemberkatski111:56 25 Sep '08  
GeneralRe: Favor... Translate VB Code to C# Pinmemberjebarson6:19 29 Sep '08  
GeneralRe: Favor... Translate VB Code to C# Pinmemberkatski117:15 2 Oct '08  
GeneralError while accessing page PinmemberSanspirit0:43 7 Apr '08  
AnswerRe: Error while accessing page Pinmemberjebarson9:41 9 Apr '08  
QuestionHow to make nested Tabstrips? PinmemberFlemming Munk19:52 28 Nov '07  
AnswerRe: How to make nested Tabstrips? Pinmemberjebarson3:33 29 Nov '07  
GeneralRe: How to make nested Tabstrips? [modified] PinmemberDane Weasel6:00 29 Nov '07  
GeneralNice PinmemberSameh Zaghloul22:46 17 Aug '07  
AnswerRe: Nice Pinmemberjebarson21:39 18 Aug '07  
GeneralExcellent! PinmemberRajLetsDoProgramming21:39 10 Jul '07  
AnswerRe: Excellent! [modified] Pinmemberjebarson2:54 11 Jul '07  
Thanks for your boost up dude. This is a function which I have written inside the javascript file. Please download the source code and go through it. Get back to me if you still dont understand.
 


 

-- modified at 10:44 Wednesday 11th July, 2007
 
Is there is anything you cant do?

GeneralCool! Pinmemberinetfly1234:10 6 Feb '07  
GeneralRe: Cool! Pinmemberjebarson23:17 6 Feb '07  
GeneralRe: but Firefox exception... Pinmemberrghubert22:43 18 Feb '07  
GeneralRe: but Firefox exception... Pinmemberjebarson4:26 19 Feb '07  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 2 Feb 2007
Article Copyright 2007 by jebarson
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid