Sharepoint .aspx页面

时间:2012-06-28 19:17:54

标签: asp.net .net sharepoint

有人告诉我,如果我不能在一天结束时解决这个问题,我将在本周末放手。我需要帮助来解决这个问题。我正在尝试为sharepoint站点创建一个.aspx页面。这是我的代码...

<script  runat="server">
Sub submit(Source As Object, e As EventArgs)
   button1.Text="You clicked me!"
End Sub
</script>

<!DOCTYPE html>
<html>
<body>

<form runat="server">
<asp:Button id="button1" Text="Click me!" runat="server" OnClick="submit" />
</form>

</body>
</html>

每次加载页面时都会收到错误消息。我从互联网上删除了这段代码,当我加载页面时,它说:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Parser Error 
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Code blocks are not allowed in this file.

Source Error: 

Line 3:     button1.Text="You clicked me!"
Line 4:  End Sub
Line 5:  </script>
Line 6:  
Line 7:  <!DOCTYPE html>

请帮帮我。为什么我收到此消息?

2 个答案:

答案 0 :(得分:1)

默认情况下,SharePoint不允许.aspx文件中的内联代码。如果要执行此操作,则需要在web.config中更改该设置,但不建议这样做。请参阅评论中发布的@Mark链接。

作为替代方案,您可以创建一个webpart,并将其添加到页面中。有关如何执行此操作的更多帮助,请参阅this article

答案 1 :(得分:0)

您可以通过在web.config文件中添加以下行来允许在sharepoint页面中添加代码

<PageParserPaths>    
  <PageParserPath VirtualPath="/pages/test.aspx" CompilationMode="Always" AllowServerSideScript="true" />    
</PageParserPaths>

其中“/pages/test.aspx”是您网页的路径,或者您可以将其添加为“/ _catalogs / masterpage / *”,例如添加所有主页文件。