Two Methods for adding background code to the moss page (2)

Source: Internet
Author: User

In this article, I will discuss with you how to add a server for the moss page Code . However, we must first declare that this method is only used for technical research. If you want to use it, please be careful!
In the previous article Article )), In this way, the code is generated as a DLL and then bound to the corresponding page, similar to ASP. net code-behind, and we know that ASP. when developing. net, you can add <SCRIPT runat = "server"> </SCRIPT> On the page to directly use the server-side code. Can this be done on the moss page? Since it is based on ASP. NET 2.0, there is no problem. I occasionally saw an article on a foreigner's blog about how to use the <SCRIPT runat = "server"> </SCRIPT> code block on the moss page. For details, see SharePoint 2007: Using ASP. NET Server Side code in your pages, so we can take advantage of it, such as writing a page_load, hosting a click event for the button, etc. The following describes in detail.
We know that adding the <SCRIPT runat = "server"> </SCRIPT> code block directly on the moss page will prompt us "An error occurred while processing XXXX. This file does not allow the use of code blocks ". What should we do? Modify web. config and add a line in <pageparserpaths> </pageparserpaths> (NO content in this node by default ):
<Pageparserpath virtualpath = "/_ catalogs/masterpage/*" compilationmode = "always" allowserversidescript = "true" includesubfolders = "true"/>
Change the path corresponding to virtualpath to your own page path. For example, in the above method, I tested it on the master page under/_ catalogs/masterpage. After saving and restarting ISS, we can add the <SCRIPT runat = "server"> </SCRIPT> code block to the page.
Extension. For example, if we want to use the page_load event of the page, we can write it like this (I use C # as an example ): first add the <SCRIPT type = "text/C #" runat = "server"> </SCRIPT> code block, and then add
Protected void page_load (Object sender, eventargs E)
{
}
In this way, we can do something we want to do during page load. For example, you can host a click event for the server-side button control on the page and add a button to the page as follows:
<Asp: button id = "button1" runat = "server" text = "Click me"> </ASP: button>
In the page_load we added above, write as follows:
Protected void page_load (Object sender, eventargs E)
{
This. button1.click + = new eventhandler (benclick );
}
Then add the event processing code b1_click. Let's let it get the text assigned to the button by the current server time when it is clicked, as shown below:
Void bid click (Object sender, eventargs E)
{
This. button1.text = datetime. Now. tostring ();
}
Return to the page and click the button to see the effect. This is just an example. The rest depends on everyone's freedom.
In terms of this information, the foreigner's blog only lists two articles. If you are interested, you can take a look:
Http://msdn2.microsoft.com/en-us/library/ms562040.aspx
Http://msdn2.microsoft.com/en-us/library/ms551625.aspx.
Once again, it is extremely insecure to add server-side code in this way. Anyone with the right to edit the page can use server-side code on the page in this way. Please use it with caution.

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.