|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThere are plenty of tabstrip controls available for download that use panels to decide which content to display. But what if your existing web application's / web site's content is stored on separate pages, or you have to use frames? This article will take you through the basics of creating a custom tabstrip control that can be loaded in one frame, and change content in another frame. Using the codeUsing the code is quite simple. The library contains a Tab control, as well as a
myTab.DisplayName = " Project Home ";
The Settings Properties
Appearance Properties
How it all works
The
This allowed me to compare one tabs display position to another, and return a
value representing whether the first tab should appear before or after
the second tab. By inheriting from the I also wanted my control to be able to have fancy images around it (you know, so it looks like a tab), so my control renders 3 html rows per tab line (the top row for the top image, the middle row for the side images and tab, and the bottom row for the bottom images). I wrote a method that returns a string for each of the rows.
The State Management
Because my TabList control inherits from Control, I can override the
//Saves the View State
protected override object SaveViewState()
{
object[] allStates = new object[2];
allStates[0] = base.SaveViewState();
allStates[1] = m_intSelTab;
return allStates;
}
//Loads View State Info 'Load Saved State Values
protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
object[] myState = (object[])savedState;
if (myState[0] != null)
{
base.LoadViewState(myState[0]);
}
if (myState[1] != null)
{
m_intSelTab = Convert.ToInt32(myState[1]);
}
}
}
In my I then loop through all my tabs and write them to the screen, using my counters to determine when to draw a new row, and when to finish off the table. I used linkbuttons as the hyperlinks, so that I could control their events server side.
protected override void CreateChildControls()
{
int intColRows = (m_items.Count / m_intTabsAcross) + 1;
int intPositionRendered = 0;
int intStartPosition = 0;
order();
this.Controls.Clear();
this.Controls.Add(new LiteralControl(
"<table cellpadding=\"2\" cellspacing=\"1\" border=\"0\" ID="Table1">"));
for (int i=1; i <= intColRows; i++)
{
if ((m_strTopImage.Length > 0) || (m_strSelTopImage.Length > 0))
{
this.Controls.Add(new LiteralControl(TopRow(intStartPosition,
ref intPositionRendered, m_intSelTab)));
}
MiddleRow(intStartPosition, ref intPositionRendered, m_intSelTab);
if ((m_strBottomImage.Length > 0) || (m_strSelBottomImage.Length > 0))
{
this.Controls.Add(new LiteralControl(BottomRow(intStartPosition,
ref intPositionRendered, m_intSelTab)));
}
intStartPosition = intPositionRendered;
}
this.Controls.Add(new LiteralControl("</table>"));
}
And that's it. I hope you find both the control (I included the dll for use), and this article useful.
|
||||||||||||||||||||||