Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

SharePoint Tabs

  Asked By: Daniel    Date: Nov 29    Category: Sharepoint    Views: 3568

I have a custom webpart that I need to add "tabs" within. I want
the "tabs" to look like the tabs that are used within SharePoint. I
can't figure out what type of tab control they are using within
SharePoint. Can someone point me in the correct direction to address
this?

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Emily Clark     Answered On: Nov 29

If you are talking about the tabs  in the top link menu bar then those are a CSS
style applied to an ASPmenu control. Not sure how you would do that inside a
web part, but you could at least tie into the same style classes.

 
Answer #2    Answered By: Alycia Everett     Answered On: Nov 29

Got any examples of how they make this menu look like a tab  control?

 
Answer #3    Answered By: Kaila Hahn     Answered On: Nov 29

The menu isn't a menu it's a server control  that can use CSS style classes to
control rendering. Here's the code from a master page that shows the classes
used.

<SharePoint:AspMenu
ID="TopNavigationMenu"
Runat="server"
DataSourceID="topSiteMap"
EnableViewState="false"
AccessKey="<%$Resources:wss,navigation_accesskey%>"
Orientation="Horizontal"
StaticDisplayLevels="2"
MaximumDynamicDisplayLevels="1"
DynamicHorizontalOffset="0"
StaticPopoutImageUrl="/_layouts/images/menudark.gif"
StaticPopoutImageTextFormatString=""
DynamicHoverStyle-BackColor="#CBE3F0"
SkipLinkText=""
StaticSubMenuIndent="0"
CssClass="ms-topNavContainer">
<StaticMenuStyle/>
<StaticMenuItemStyle CssClass="ms-topnav"
ItemSpacing="0px"/>
<StaticSelectedStyle
CssClass="ms-topnavselected" />
<StaticHoverStyle CssClass="ms-topNavHover" />
<DynamicMenuStyle BackColor="#F2F3F4"
BorderColor="#A7B4CE" BorderWidth="1px"/>
<DynamicMenuItemStyle
CssClass="ms-topNavFlyOuts"/>
<DynamicHoverStyle
CssClass="ms-topNavFlyOutsHover"/>
<DynamicSelectedStyle
CssClass="ms-topNavFlyOutsSelected"/>
</SharePoint:AspMenu>

 
Answer #4    Answered By: Ada Sosa     Answered On: Nov 29

I got this working within a custom  webpart and thought I would
share. :) The only thing that I don't like - is I can't figure  out a
way to space or put a seperator between the menu items.

Hope this helps someone else.

So from CreateChildControls I call BuildTabMenu...

/// <summary>
/// TabMenu
/// </summary>
public System.Web.UI.WebControls.Menu tabMenu;
protected List<MenuItem> tabMenuItems = new List<MenuItem>();

protected override void CreateChildControls()
{
try
{
BuildTabMenu();

...........

Here is the guts of the tab  menu....

/// <summary>
/// This function builds the tabmenu
/// </summary>
protected void BuildTabMenu()
{
try
{
// create the menu that looks like tabs
tabMenu = new System.Web.UI.WebControls.Menu();
tabMenu.MenuItemClick += new MenuEventHandler
(tabMenu_MenuItemClick);
tabMenu.Orientation = Orientation.Horizontal;
tabMenu.ID = "TabMenu";
tabMenu.EnableViewState = false;
tabMenu.StaticDisplayLevels = 2;
tabMenu.MaximumDynamicDisplayLevels = 1;
tabMenu.DynamicHorizontalOffset = 0;
tabMenu.StaticPopOutImageUrl
= "/_layouts/images/menudark.gif";
tabMenu.StaticPopOutImageTextFormatString = "";
tabMenu.DynamicHoverStyle.BackColor =
ColorTranslator.FromHtml("#CBE3F0");
tabMenu.SkipLinkText = "";
tabMenu.StaticSubMenuIndent = new Unit(1);
tabMenu.CssClass = "ms-topNavContainer";
tabMenu.StaticMenuStyle.CssClass = "ms-topnav";
tabMenu.StaticSelectedStyle.CssClass = "ms-
topnavselected";
tabMenu.StaticHoverStyle.CssClass = "ms-topNavHover";
tabMenu.DynamicMenuStyle.BackColor =
ColorTranslator.FromHtml("#F2F3F4");
tabMenu.DynamicMenuStyle.BorderColor =
ColorTranslator.FromHtml("#A7B4CE");
tabMenu.DynamicMenuStyle.BorderWidth = new Unit(1);
tabMenu.DynamicMenuStyle.CssClass = "ms-
topNavFlyOuts";
tabMenu.DynamicHoverStyle.CssClass = "ms-
topNavFlyOutsHover";
tabMenu.DynamicSelectedStyle.CssClass = "ms-
topNavFlyOutsSelected";

foreach (MenuItem menuItem in tabMenuItems)
{
tabMenu.Items.Add(menuItem);
}
}
catch (Exception ex)
{
labelError.Text = "ControlsWP.BuildTabMenu Err: " +
ex.Message;
Utilities.EventLogHelper.WriteToLog(EventLogname,
labelError.Text, System.Diagnostics.EventLogEntryType.Error);
}
}

/// <summary>
/// This function is an override from the base class that
allows the menu items to be added to the tab control.
/// </summary>
protected override void PopulateMenuItems()
{
try
{
MenuItem item1 = new MenuItem();
item1.Text = "Test";
item1.ToolTip = "Test";
tabMenuItems.Add(item1);

MenuItem item2 = new MenuItem();
item2.Text = "Test2";
item2.ToolTip = "Test2";
tabMenuItems.Add(item2);

MenuItem item3 = new MenuItem();
item3.Text = "Test3";
item3.ToolTip = "Test3";
tabMenuItems.Add(item3);
}
catch (Exception ex)
{
labelError.Text += "SchoolsWP.PopulateMenuItems()
Err: " + ex.Message;
Utilities.EventLogHelper.WriteToLog(EventLogname,
labelError.Text, System.Diagnostics.EventLogEntryType.Error);
}
}

/// <summary>
/// This is the render function for the webpart
/// </summary>
/// <param name="writer"></param>
protected override void Render(HtmlTextWriter writer)
{
try
{

// adds the tab menu if there are menuitems in the
tab menu
tabMenu.RenderControl(writer);

 
Answer #5    Answered By: Aditya Da costa     Answered On: Dec 02

Hi, I did try the above code and i get this error

Error 1 'MenuItem' is an ambiguous reference between 'System.Web.UI.WebControls.MenuItem' and 'Microsoft.SharePoint.WebPartPages.MenuItem'

when i declare the below statements
public System.Web.UI.WebControls.Menu tabMenu;
protected List<MenuItem> tabMenuItems = new List<MenuItem>();

can you just guide me.

 
Didn't find what you were looking for? Find more on SharePoint Tabs Or get search suggestion and latest updates.




Tagged: