|
|||||||||||||||||||||
|
|||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionWindows Forms Web TabStrip Visual DesignThe
Carefully selecting these 10 color attributes will give a Web Tab visual effect as shown below:
To implement this Web Repeater Control ItemCommand EventWhen a user clicks on a tab, the private void __theTabStrip_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
CurrentTabIndex = e.Item.ItemIndex;
....
}
Basically, server side code will now know which tab is clicked through the event argument and can do the color setting accordingly: <ItemTemplate>
<asp:Button Runat=server .. BackColor="<%# SetTabBackColor(Container) %>" .. />
</ItemTemplate>protected Color SetTabBackColor(object elem)
{
RepeaterItem item = (RepeaterItem) elem;
if (item.ItemIndex==CurrentTabIndex) return SelectedTabBackColor;
return TabBackColor;
}
Note that ASP.NET Runtime can mix up "Angle Bracket" code with object code as seen here, especially code binding Functions to tag attributes using " You may have noticed that we have been using Web User Control State ManagementASP.NET Web User Control allows persisting state using ViewState and initializing state using "Angle Bracket" 's Attributes, which correspond to object property: <uc1:TabStrip id="TabStrip1" runat="server"
SelectedTabBackColor="#003333"
TabForeColor="Black"
TabBackColor="#669999"
SelectedTabForeColor="White"
TabStripBackColor="White"
SelectedSubTabBackColor="#003333"
SubTabForeColor="Yellow"
SubTabBackColor="#003333"
SelectedSubTabForeColor="White"
SubTabStripBackColor="#003333" />
public Color TabBackColor
{
get {return (Color) ViewState["TabBackColor"]; }
set { ViewState["TabBackColor"]=value;}
}
public int CurrentTabIndex
{
get {return (int) ViewState["CurrentTabIndex"]; }
}
These excellent infrastructure support from ASP.NET Runtime enables us to write simple color changing code in previous section. WARNING: ViewState takes bandwidth. So you may consider using Session State instead. Now we have all the code for color change responding to user click action. How do we then change content of the hosting page upon user's click action? Designing Web TabStrip EventClearly, this public class SelectionChangedEventArgs : EventArgs
{
public int TabPosition;
public int SubTabPosition=0;
}
public delegate void SelectionChangedEventHandler(object sender,
SelectionChangedEventArgs e);
public event SelectionChangedEventHandler SelectionChanged;
public void SelectTab(int index)
{
....
SelectionChangedEventArgs ev= new SelectionChangedEventArgs();
ev.TabPosition= index;
ev.SubTabPosition=(int) ViewState["CurrentSubTabIndex"];
if( SelectionChanged !=null) SelectionChanged(this,ev);
}
Note that this function will be called in To respond to these events on hosting pages, we need the following on hosting pages: TabStrip ts = (TabStrip) this.FindControl("TabStrip1");
....
ts.SelectionChanged+=new SelectionChangedEventHandler(ts_SelectionChanged);
private void ts_SelectionChanged(object sender,
JQD.SelectionChangedEventArgs e)
{
// your code here
}
In my event handler function, I set the source of a Note that Final Words on DataBindingWe have seen how <TD id="TabStripTD">
<asp:repeater id=__theTabStrip runat="server"
DataSource='<%# DataBinder.Eval(Container,"TabText") %>'>
<ItemTemplate>
<asp:Button Runat=server Text="<%# Container.DataItem %>" ... />
....
Note that " public ArrayList TabText
{
get {return _TabText; }
set { _TabText=value; }
}
I chose not to persist How to use Web TabStrip User Control in your Web ProjectI have included a sample project showing how to use the control. Do the following if you need to include this Web User Control in your Web Application Project:
Note that I have run the sample and these steps on Windows 2003 with Framework 1.1. Finally, if you decided to run my sample directly, you will need to extract the zip file into an IIS virtual directory "TestTabStrip", and open the solution there, and you should see the screen as below:
ConclusionI have presented to you a simple and generic Web | ||||||||||||||||||||