zoukankan      html  css  js  c++  java
  • 让用户控件包装器“见鬼”去。

    把用户控件装载到到WebPart里面,在实际的项目中,我们有时候需要用很多用户控件在MOSS里面,如果用,用户控件包装器的话,客户一看就显示的很不专业,也影响公司的形象,所以,做项目的时候需要把用户控件包装成WebPart,这样就显示的稍微的好点咯。。。嘿嘿。
    其实也很简单,
    1。 步骤1写好自己的用户控件,然后,把他用户控件的页面放到
    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES\WpLoadUc\AddUserControl.ascx下面
    然后把dll放到相应的moss bin 下面 或GAC
    2。写一个WebPart,很简单,代码如下:

    using System;
    using System.Runtime.InteropServices;
    using System.Web.UI;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Serialization;

    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
    using Microsoft.SharePoint.WebPartPages;

    namespace WPLoadUserControl
    {
        [Guid("0d2c817f-71c3-4349-b813-cf8eb81f4bd5")]
        public class WPLoadUserControl : System.Web.UI.WebControls.WebParts.WebPart
        {
            protected Control userControl;
            public WPLoadUserControl()
            {
                this.ExportMode = WebPartExportMode.All;
            }

            protected override void CreateChildControls()
            {
                //base.CreateChildControls();

                this.Controls.Clear();
                string userControlPath = @"/_controltemplates/WpLoadUc/AddUserControl.ascx";
                this.userControl = this.Page.LoadControl(userControlPath);
                this.Controls.Add(this.userControl);

            }
            protected override void Render(HtmlTextWriter writer)
            {
                // TODO: add custom rendering code here.
                 writer.Write("Show AA");
                 this.userControl.RenderControl(writer);

            }

        }
    }
    代码是不是很简单哦,WebPart 的部署就不用我说啦。。。
    3,然后修改下配置文件
    <SafeControl src="~/_controltemplates/WpLoadUc/*" IncludeSubFolders="True" Safe="True" AllowRemoteDesigner="True" />

    嘿嘿 指定到相应的用户控件哦。
    哈哈哈 ,各位是不是很简单,,嘿嘿快去测试哦。/
    。。。。。。。。。。。。。
    代码不是最好的,只是供大家参考。。

  • 相关阅读:
    [读书笔记]-技术学习-微服务架构与实践
    [文章转载]-Java后端,应该日常翻看的中文技术网站 -江南白衣
    [文章转载]-我的Java后端书架-江南白衣
    正则表达式有多强大一看便知!
    微信小程序支付功能完整流程
    判断字符串是否合法(1)
    ES6新增常用方法
    JS求一个字符串在另一个字符串中出现的次数
    根据对象的某个属性排序
    数组去除重复值的四种超简便方法
  • 原文地址:https://www.cnblogs.com/cxd4321/p/873131.html
Copyright © 2011-2022 走看看