【发布时间】:2019-05-10 19:59:50
【问题描述】:
我需要将一个 ASP.NET Web 表单页面添加到我的 ASP.NET API 项目中。这是一个遗留应用程序,我还没有时间移植到 API 和 Angular。旧页面包含多个控件,包括文本框、下拉列表和 GridView 控件。 Web 表单的所有代码逻辑都包含在代码隐藏页面中。
我遇到的问题是,当我尝试重建项目时,无法识别旧版 Web 表单中的控件。我收到以下错误
Error CS0103 The name '<name of web control>' does not exist in the current context MyWebApp C:\source_code\MyWebApp\api\services\LegacyWebForm.aspx.cs
对于 ASPX 页面上的所有服务器端控件,我都遇到了这些错误之一。
我很确定我可以在 API 应用程序中运行这个旧版 Web 表单,我需要做的就是添加...
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
我的代码隐藏文件LegacyWebForm.aspx.cs继承自System.Web.UI.Page,ASPX页面继承页面类
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LegacyWebForm.aspx.cs" Inherits="MyWebApp.api.services.LegacyWebForm" %>
代码隐藏类名
namespace MyWebApp.api.services
{
public partial class LegacyWebForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
...
【问题讨论】:
-
应该是有效的,你不是缺少runats吗?
-
我在包含
<form>元素和所有控件上确实有runat="server" -
你的
.aspx.designer.cs注册了吗? (protected global::System.Web.UI.WebControls.TextBox someTextBox;,那个文件有正确的命名空间吗? -
Designer 它将在文件层次结构中与文件
.aspx.cs代码后面的.aspx.cs代码相邻regenerating the designer -
@UK_Dev - 做到了!您提供给Designer 的链接包含重新生成 .aspx.designer.cs 文件的所有说明。之后它编译并运行。非常感谢!仅供参考 -
David-Dietrich的答案包含我遵循的步骤。
标签: asp.net asp.net-web-api webforms