Add background code for Sharepoint

Source: Internet
Author: User

 

Reprinted: http://blog.csdn.net/RainyLin/archive/2009/01/15/3789922.aspx

 

We know that the SharePoint page stored in the database cannot directly add background code, which makes us inconvenient. For example, we want to implement something on the page, webpart or custom control must be used, even if it is just a few simple lines of background code. WSS 3.0 is based on ASP. NET 2.0. Any technology used in ASP. NET sites can also be used in WSS sites. Therefore, we can also add background code to the page of The WSS site.

The SharePoint page stored in the database is divided into two departments: the dashboard page and the content page. We can add background code for the two pages respectively. The implementation method is different. If you add background code to the content page, we need to inherit from Microsoft. sharepoint. publishing. publishinglayoutpage class. If you add background code to the dashboard page, we need to inherit from system. web. UI. masterpage class. You should set the background code class to the same name as the corresponding page, but this is not necessary. As follows:
Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using Microsoft. SharePoint;
Using Microsoft. Sharepoint. publishing;
Using Microsoft. Sharepoint. webcontrols;
Namespace AA {
Public class aaclass: publishinglayoutpage {
}
}
In this way, we can add the corresponding background code for the controls on the page. For example, there is a button and a text box on our page. The ID is textbox1 and button1 respectively, and a ckick event is added to the button. When you click the button, the current time is written to the text box, you can write it like this:
Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using Microsoft. SharePoint;
Using Microsoft. Sharepoint. publishing;
Using Microsoft. Sharepoint. webcontrols;
Namespace AA
{
Public class aaclass: publishinglayoutpage
{
Protected textbox textbox1;
Protected button button1;
Protected override void oninit (eventargs E)
{
Base. oninit (E );
Button1.click + = new eventhandler (button#click );
}
}
Void button#click (Object sender, eventargs E)
{
Textbox1.text = datetime. Now. tostring ();
}
}
On the moss page, server controls are divided into ASP controls (namespace system. web. UI. webcontrols and SharePoint controls (The namespace is Microsoft. sharepoint. webcontrols), we can also declare SharePoint controls and add corresponding operations for them.
After writing our background code, generate the code to the corresponding bin directory (or GAC, remember to name it) on the web. add a line to the config file, <safecontrol Assembly = "" namespace = "" typename = "*" Safe = "true"/>, where assembly and namespace can be obtained through reflector, then we need to rewrite the page on the page:
<% @ Page meta: progid = "Sharepoint. webpartpages. document "Language =" C # "inherits =" mosscodebehind. codebehind, mosscodebehind, version = 1.0.0.0, culture = neutral, publickeytoken = NULL "%>
If it is a motherboard page, add
<% @ Master language = "C #" inherits = "mosscodebehind. codebehind, mosscodebehind, version = 1.0.0.0, culture = neutral, publickeytoken = NULL" %>

After rewriting, the page cannot be opened in the design window.

In this way, developers can develop in the same way as ASP. NET. For example, we can rewrite the onload event to bind data to the page control.
If you are interested, you can try it to meet many of our needs.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.