• 让用户控件包装器“见鬼”去。


    把用户控件装载到到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" />

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

  • 相关阅读:
    【引用】将WINNT.XPE安装到移动硬盘的方法
    手把手教你把Vim改装成一个IDE编程环境(图文)(转)
    [转载]经验丰富的程序员和代码行数
    pkgconfig的使用(转)
    焦点新闻总结
    仿百度弹出框在框架页面中的应用
    发现不明确的匹配的原因和解决办法
    总结一个DAL中写IList返回实体的方法
    后台管理系统界面和样式,点击左边新建标签效果
    在用户控件中用户登录后台脚本判断
  • 原文地址:https://www.cnblogs.com/cxd4321/p/873131.html
Copyright © 2020-2023  润新知