没有代码的 ASP.net 页面 [英] ASP.net page without a code behind

查看:16
本文介绍了没有代码的 ASP.net 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 C# 代码的 ASP.Net 页面.

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

但是,我被要求不要使用隐藏代码 - 以便在 SharePoint 中部署更容易.

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

有没有办法在 ASP.Net 页面中包含 C# 代码,而不使用单独的代码隐藏文件?

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

推荐答案

默认情况下,Sharepoint 不允许在 ASPX 文件中执行服务器端代码.参见此如何解决.

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

但是,我想指出在 Sharepoint 中部署代码隐藏不一定很难(我们广泛部署)-只需将代码隐藏类编译成程序集并使用 解决方案.

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>

这篇关于没有代码的 ASP.net 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆