Custom PublishingLayoutPage(moss page to add codebehind code)

First: Create WSPBuilder Project. Then create a cs file inherit PublishinglayoutPage

Code is like the following:

MossCodeBehind 类库:

using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;
using System.Web.UI.WebControls;

namespace MossCodeBehind
{
    public class CodeBehind : PublishingLayoutPage
    {
        protected TextBox textbox1;
        protected Button button1;
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            button1.Click += new EventHandler(button1_Click);
        }

        void button1_Click(object sender, EventArgs e)
        {
            textbox1.Text = DateTime.Now.ToString();
        }
    }
}


CodeBehind.aspx页面:

<%@ Page meta:progid="SharePoint.WebPartPages.Document" Language="C#"
MasterPageFile="~masterurl/default.master"  
Inherits="MossCodeBehind.CodeBehind,
MossCodeBehind,   Version=1.0.0.0, Culture=neutral, PublicKeyToken=e53f6b6d46a6bfe9" %>

<asp:Content ContentPlaceHolderID="PlaceHolderGlobalNavigationSiteMap" runat="server">
<body>
<form id="form1" runat="server">
<asp:TextBox runat="server" id="TextBox1"></asp:TextBox>
<asp:Button runat="server" Text="Button" id="Button1"/>
</form>
</body>
</asp:Content>

Second: Compile the code, Copy this dll into GAC. Use cmd gacutil –I dll. Then modify the webconfig

(C:/Inetpub/wwwroot/wss/VirtualDirectories/41305/).

Add <safecontrol>

Third: site action—create page(choose blank web part layout).Then modify this page using share point designer. Steps for modifying  the UI  page.

·         Detach from page layout

·         Check out, add control which is needed in cs file. If we do not add the control. We’ll run into error. error message: Object reference not set to an instance of an object

·         Lastly, we’ll instead the page(only one line other is not be modified) in header.

"<%@ Page....", replace for "<%@ Page meta:progid="SharePoint.WebPartPages.Document" Language="C#" Inherits="namespace.class, namespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=de36ee2169a5aec4" %>"

 

 

We can get namespace and publickkeytoken using reflector tool.

Note: 代码出现串值问题,主要原因是不能把它作为layout而是页面,这样就不会出现因多线程引起的串值问题了.

Error:Can not load assamble"",make sure you combiled it before the page is loading.

Solution:first:strong name sencond:web config added is not correct.  

References: http://msdn.microsoft.com/en-us/library/bb986729(office.12).aspx

http://blogs.msdn.com/b/jannemattila/archive/2007/04/14/adding-functionalities-to-pages-by-inheriting-publishingpagelayout.aspx 

http://bbs.winos.cn/viewthread.php?action=printable&tid=36766

http://bbs.winos.cn/thread-36766-1-6.html

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值