背景:sharepoint的左侧快速链接不能满足我们的需要,我们需要根据登陆用户加载不同的菜单,根据用户的不同语言版本加载不同语言的左侧快速导航。
直接上控件代码:
public class CustomeMenu : WebControl { protected override void CreateChildControls() { base.CreateChildControls(); Table table = new Table(); table.CellPadding = 0; table.CellSpacing = 0; TableRow row_Menu = new TableRow(); TableCell cell_Menu = new TableCell(); cell_Menu.Text = "互联网"; row_Menu.Cells.Add(cell_Menu); table.Rows.Add(row_Menu); TableRow row_Menu2 = new TableRow(); TableCell cell_Menu2 = new TableCell(); cell_Menu2.Text = "---百度"; row_Menu2.Cells.Add(cell_Menu2); table.Rows.Add(row_Menu2); TableRow row_Menu3 = new TableRow(); TableCell cell_Menu3 = new TableCell(); cell_Menu3.Text = "---腾讯"; row_Menu3.Cells.Add(cell_Menu3); table.Rows.Add(row_Menu3); TableRow row_Menu4 = new TableRow(); TableCell cell_Menu4 = new TableCell(); cell_Menu4.Text = "水果"; row_Menu4.Cells.Add(cell_Menu4); table.Rows.Add(row_Menu4); TableRow row_Menu5 = new TableRow(); TableCell cell_Menu5 = new TableCell(); cell_Menu5.Text = "---苹果"; row_Menu5.Cells.Add(cell_Menu5); table.Rows.Add(row_Menu5); TableRow row_Menu6 = new TableRow(); TableCell cell_Menu6 = new TableCell(); cell_Menu6.Text = "---桃子"; row_Menu6.Cells.Add(cell_Menu6); table.Rows.Add(row_Menu6); } }
将dll签名注册到GAC中,再修改web.config,将该控件加到安全控件中。
<SafeControl Assembly="ControlLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=590e3f83bda9d281" Namespace="ControlLibrary" TypeName="*" Safe="True" SafeAgainstScript="False" />
重启IIS,用Designer打开v4.master,将左侧导航隐藏。
<div style="display:none">
<Sharepoint:SPNavigationManager
id="QuickLaunchNavigationManager"
runat="server"
QuickLaunchControlId="QuickLaunchMenu"
ContainedControl="QuickLaunch"
EnableViewState="false"
CssClass="ms-quicklaunch-navmgr">
</div>
添加我们自己的自定义控件
<%@ Register Tagprefix="ControlLibrary" Namespace="ControlLibrary" Assembly="ControlLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=590e3f83bda9d281" %>
然后再<Sharepoint:SPNavigationManager>上面添加
<ControlLibrary:CustomeMenu runat="server"></ControlLibrary:CustomeMenu>
我们自定义控件就生成了。