2-9SharePoint 用户控件得使用
添加解决方案——>添加映射文件夹——>TEMPLATE——>CONTROLTEMPLATES

添加用户控件

<div> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> </div>
using Microsoft.SharePoint; using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; namespace CustomUserControlTwo.CONTROLTEMPLATES { public partial class CustomUserControlTwo : UserControl { public string url = "http://www.baidu.com"; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Label1.Text = SPContext.Current.Web.CurrentUser.Name; } } protected void Button1_Click(object sender, EventArgs e) { Page.Response.Redirect(url); } } }
母版页注册并使用



<%@ Register TagPrefix="ucl" TagName="CustomUserControlTwo" src="~/_controltemplates/15/CustomUserControlTwo.ascx" %>
<asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server"> <div> <ucl:CustomUserControlTwo id ="CustomUserControlTwo1" url="http://www.jd.com" runat="server"></ucl:CustomUserControlTwo> </div> <div id="searchInputBox"> <SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" /> </div> </asp:ContentPlaceHolder>
效果,欢迎


浙公网安备 33010602011771号