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://bbs.winos.cn/viewthread.php?action=printable&tid=36766
http://bbs.winos.cn/thread-36766-1-6.html