Tuesday, May 13, 2008

Sharepoint Inline C# Code

You could add inline C# code to a page that is created by Sharepoint designer. For example, you could show or hide a panel by the query string. Or you could handle a button click event and so on. In this case I added the following code to the NewsletterSearch.aspx page in Sharepoint designer:

<script runat="server">

protected void Page_Load(object sender, EventArgs e)


if (Request.QueryString["k"] == null)


pnlSearchResults.Visible = false;




pnlNewsletters.Visible = false;




Then you need to modify the application's web.config in the virtual directory folder. Under the SafeMode node, add the following:


<PageParserPath VirtualPath="/Newsletter/NewsletterSearch.aspx" CompilationMode="Always" AllowServerSideScript="true" />



Code-blocks are not allowed in this file: Using Server-Side Code with SharePoint

blog comments powered by Disqus