Search code examples
c#.netasp.netsharepointcode-behind

ASP.net page without a code behind


I have an ASP.Net page with a C# code behind.

However, I've been asked to not use a code behind - so that it will be easier to deploy in SharePoint.

Is there a way to include the C# code in the ASP.Net page, without using a separate code behind file?


Solution

  • By default Sharepoint does not allow server-side code to be executed in ASPX files. See this for how to resolve that.

    However, I would raise that having a code-behind is not necessarily difficult to deploy in Sharepoint (we do it extensively) - just compile your code-behind classes into an assembly and deploy it using a solution.

    If still no, you can include all the code you'd normally place in a codebehind like so:

    <script language="c#" runat="server">
    public void Page_Load(object sender, EventArgs e)
    {
      //hello, world!
    }
    </script>