|
||
|
Obsolete feature
This feature is now obsolete. If you need to customize the behavior of some web part, please clone the web part and customize it.
If you still need to use this feature (for backward compatibility), you need to enable it by adding the following parameter to your web.config file, to the appSettings section:
|
|
Limitations when using the Code tab
If you add custom code on the Code tab, you will not be able to pre-compile the website and you will not be able to use the website in a medium trust environment. If this is an issue for you, you can use the alternative solutions described in this chapter. |
If you need to modify the behavior or enhance the functionality of some web part only on a single page template, you can add custom code on the Code tab:
The following code displays the current date and time below the current web part:
[C#]
<asp:Label runat="server" id="lblTime"></asp:Label> <script runat="server"> protected override void OnLoad(EventArgs e) { base.OnLoad(e); this.lblTime.Text = "The time is: " + DateTime.Now.ToString(); } </script> |
|
Programming language
Please note: You can only use the programming language in which the web part is written. If the web part was written in C#, you can use only C# here.
|
The following code sample sets the WhereCondition property of the web part dynamically at run-time:
[C#]
<script runat="server"> public override void OnContentLoaded() { this.SetValue("WhereCondition", "NewsTitle LIKE '%News%'"); base.OnContentLoaded(); } </script> |
|
Calling the original method from the inherited class
If you override some method of the web part, please be sure to always also call the original method (using base.Method in C# or MyBase.Method in VB). If you omit this, the web part may not work properly. |