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>

效果,欢迎

posted @ 2020-05-25 12:43  七秒钟得记忆  阅读(93)  评论(0)    收藏  举报