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?
One tactic for separating code from presentation in ASP.NET is code behind. Code behind is a feature that enables you to take most of or all the code out of an ASP.NET page and place it in a separate file. The code is processed normally; the only difference is where the code is located.
Add("style","display:none"); div_id: id which you want to hide. Attributes: that will use value. Add: keyword will add the attribute.
The primary goal of the code-behind file is to enable you to write more modular code so that you can keep the code and layout physically separate. By keeping the code and layout separate, you can exploit the native object orientation of the .
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>
You can actually have all the code in the aspx page. As explained here.
Sample from here:
<%@ Language=C# %> <HTML> <script runat="server" language="C#"> void MyButton_OnClick(Object sender, EventArgs e) { MyLabel.Text = MyTextbox.Text.ToString(); } </script> <body> <form id="MyForm" runat="server"> <asp:textbox id="MyTextbox" text="Hello World" runat="server"></asp:textbox> <asp:button id="MyButton" text="Echo Input" OnClick="MyButton_OnClick" runat="server"></asp:button> <asp:label id="MyLabel" runat="server"></asp:label> </form> </body> </HTML>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With