方法一(如何使用微软提供的控件):
Open your master page either within SharePoint Designer, Visual Studio, Notepad, etc. Add a Register TagPrefix to the page (if it isn’t already present)
<%@ Register TagPrefix=”PublishingVariations” TagName=”VariationsLabelMenu” src=”~/_controltemplates/VariationsLabelMenu.ascx” %> Place the Variation Menu Label (where you would like it to show up) between the <Form></Form> as follows:
<PublishingVariations:VariationsLabelMenu id=”labelmenu1″ runat=”server”/> Check In & Publish the Master page On your sharepoint server(s) open the ‘VariationsLabelMenu.ascx’ file in notepad - file location: %DRIVE%\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES\ You will see that the cms:VariationsLabelIEcbMenu is outcommented with <%– –%> comments. Remove these comment tags and save the file. Your VariationsLabelMenu works fine now!
注:经过测试发现,其实不需要自行在MasterPage中添加该控件,MasterPage已经包含一段显示该控件的代码:<SharePoint:DelegateControl runat="server" ControlId="GlobalSiteLink0"/>
方法二(我自己实现的控件):
<%
@ Control Language
=
"
C#
"
ClassName
=
"
MultiLanguageMenu
"
%>
<% @ Assembly Name = " Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c " %>
<% @ Import Namespace = " System " %>
<% @ Import Namespace = " System.Collections " %>
<% @ Import Namespace = " System.Web.UI " %>
<% @ Import Namespace = " System.Web.UI.WebControls " %>
<% @ Import Namespace = " Microsoft.SharePoint " %>
<% @ Import Namespace = " Microsoft.SharePoint.Publishing " %>
< script runat = " server " >
private bool visable = true ;
private string itemCssClass = string .Empty;
private string menuCssClass = string .Empty;
private string normalCssClass = string .Empty;
private string activeCssClass = string .Empty;
private string mLeaveScript = string .Empty;
private string mEnterScript = string .Empty;
private string mClickScript = string .Empty;
protected void Page_Load( object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
mLeaveScript = "document.getElementById('{0}').className = '{1}'; document.getElementById('{2}').style.display = 'none';";
mEnterScript = "document.getElementById('{0}').className = '{1}';";
mClickScript = "document.getElementById('{0}').style.display = 'block';";
pnlItem.Attributes.Add("onmouseleave", string.Format(mLeaveScript, pnlCurVariation.ClientID, normalCssClass, pnlMenuHold.ClientID));
pnlCurVariation.Attributes.Add("onmouseenter", string.Format(mEnterScript, pnlCurVariation.ClientID, activeCssClass));
pnlCurVariation.Attributes.Add("onclick", string.Format(mClickScript, pnlMenuHold.ClientID));
pnlItem.Visible = visable;
pnlItem.CssClass = itemCssClass;
pnlCurVariation.CssClass = normalCssClass;
pnlMenu.CssClass = menuCssClass;
CreateMenu();
}
catch (Exception ex)
{
lblCurVariation.Text = ex.Message;
}
}
}
public bool Visable
{
get { return visable; }
set { visable = value; }
}
public string ItemCssClass
{
get { return itemCssClass; }
set { itemCssClass = value; }
}
public string MenuCssClass
{
get { return menuCssClass; }
set { menuCssClass = value; }
}
public string NormalCssClass
{
get { return normalCssClass; }
set { normalCssClass = value; }
}
public string ActiveCssClass
{
get { return activeCssClass; }
set { activeCssClass = value; }
}
private void CreateMenu()
{
ArrayList varList = new ArrayList();
foreach (VariationLabel varLabel in Variations.Current.UserAccessibleLabels)
{
if (varLabel.Locale == SPContext.Current.Web.Locale.LCID.ToString())
{
lblCurVariation.Text = varLabel.DisplayName;
}
else
{
varList.Add(varLabel);
}
}
dlVariations.DataSource = varList;
dlVariations.DataBind();
}
</ script >
< asp:Panel ID = " pnlItem " runat = " server " >
< asp:Panel ID = " pnlCurVariation " runat = " server " >
< asp:Label ID = " lblCurVariation " runat = " server " Text = " Language Not Found " ></ asp:Label >< asp:Image ID = " Image1 "
runat = " server " ImageUrl = " ~/_layouts/images/menudark.gif " ImageAlign = " textTop " />< br />
</ asp:Panel >
< asp:Panel ID = " pnlMenuHold " runat = " server " Style = " display: none; position: absolute;
z - index: 20 ; " >
< iframe style = " position: absolute; z-index: -1; filter: alpha(opacity=0); " ></ iframe >
< asp:Panel ID = " pnlMenu " runat = " server " >
< asp:DataList ID = " dlVariations " runat = " server " RepeatLayout = " Flow " >
< ItemTemplate >
< asp:HyperLink ID = " HyperLink1 " NavigateUrl = ' <%# DataBinder.Eval(Container, "DataItem.TopWebUrl")%> '
runat = " server " Width = " 100% " ><% # DataBinder.Eval(Container, " DataItem.DisplayName " ) %></ asp:HyperLink >
</ ItemTemplate >
</ asp:DataList >
</ asp:Panel >
</ asp:Panel >
</ asp:Panel >
<% @ Assembly Name = " Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c " %>
<% @ Import Namespace = " System " %>
<% @ Import Namespace = " System.Collections " %>
<% @ Import Namespace = " System.Web.UI " %>
<% @ Import Namespace = " System.Web.UI.WebControls " %>
<% @ Import Namespace = " Microsoft.SharePoint " %>
<% @ Import Namespace = " Microsoft.SharePoint.Publishing " %>
< script runat = " server " >
private bool visable = true ;
private string itemCssClass = string .Empty;
private string menuCssClass = string .Empty;
private string normalCssClass = string .Empty;
private string activeCssClass = string .Empty;
private string mLeaveScript = string .Empty;
private string mEnterScript = string .Empty;
private string mClickScript = string .Empty;
protected void Page_Load( object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
mLeaveScript = "document.getElementById('{0}').className = '{1}'; document.getElementById('{2}').style.display = 'none';";
mEnterScript = "document.getElementById('{0}').className = '{1}';";
mClickScript = "document.getElementById('{0}').style.display = 'block';";
pnlItem.Attributes.Add("onmouseleave", string.Format(mLeaveScript, pnlCurVariation.ClientID, normalCssClass, pnlMenuHold.ClientID));
pnlCurVariation.Attributes.Add("onmouseenter", string.Format(mEnterScript, pnlCurVariation.ClientID, activeCssClass));
pnlCurVariation.Attributes.Add("onclick", string.Format(mClickScript, pnlMenuHold.ClientID));
pnlItem.Visible = visable;
pnlItem.CssClass = itemCssClass;
pnlCurVariation.CssClass = normalCssClass;
pnlMenu.CssClass = menuCssClass;
CreateMenu();
}
catch (Exception ex)
{
lblCurVariation.Text = ex.Message;
}
}
}
public bool Visable
{
get { return visable; }
set { visable = value; }
}
public string ItemCssClass
{
get { return itemCssClass; }
set { itemCssClass = value; }
}
public string MenuCssClass
{
get { return menuCssClass; }
set { menuCssClass = value; }
}
public string NormalCssClass
{
get { return normalCssClass; }
set { normalCssClass = value; }
}
public string ActiveCssClass
{
get { return activeCssClass; }
set { activeCssClass = value; }
}
private void CreateMenu()
{
ArrayList varList = new ArrayList();
foreach (VariationLabel varLabel in Variations.Current.UserAccessibleLabels)
{
if (varLabel.Locale == SPContext.Current.Web.Locale.LCID.ToString())
{
lblCurVariation.Text = varLabel.DisplayName;
}
else
{
varList.Add(varLabel);
}
}
dlVariations.DataSource = varList;
dlVariations.DataBind();
}
</ script >
< asp:Panel ID = " pnlItem " runat = " server " >
< asp:Panel ID = " pnlCurVariation " runat = " server " >
< asp:Label ID = " lblCurVariation " runat = " server " Text = " Language Not Found " ></ asp:Label >< asp:Image ID = " Image1 "
runat = " server " ImageUrl = " ~/_layouts/images/menudark.gif " ImageAlign = " textTop " />< br />
</ asp:Panel >
< asp:Panel ID = " pnlMenuHold " runat = " server " Style = " display: none; position: absolute;
z - index: 20 ; " >
< iframe style = " position: absolute; z-index: -1; filter: alpha(opacity=0); " ></ iframe >
< asp:Panel ID = " pnlMenu " runat = " server " >
< asp:DataList ID = " dlVariations " runat = " server " RepeatLayout = " Flow " >
< ItemTemplate >
< asp:HyperLink ID = " HyperLink1 " NavigateUrl = ' <%# DataBinder.Eval(Container, "DataItem.TopWebUrl")%> '
runat = " server " Width = " 100% " ><% # DataBinder.Eval(Container, " DataItem.DisplayName " ) %></ asp:HyperLink >
</ ItemTemplate >
</ asp:DataList >
</ asp:Panel >
</ asp:Panel >
</ asp:Panel >