0

I need to add an ASP.NET web form pages to my ASP.NET API project. This is a legacy app that I don't have time to port over to the API & Angular just yet. The legacy page contains several controls including text boxes, drop down lists and a GridView control. All the code logic for the web form is contained in the code-behind page.

The problem I am running into is that when I try and rebuild the project the controls in the legacy web form are not recognized. I get the following error

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

I get one of these errors for all the server side controls on the ASPX page.

I was pretty sure I could run this legacy web form inside of the API application and all I needed to do was add ...

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

My code behind file LegacyWebForm.aspx.cs inherits from System.Web.UI.Page and the ASPX page inherits the page class

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LegacyWebForm.aspx.cs" Inherits="MyWebApp.api.services.LegacyWebForm" %>

code-behind class name

namespace MyWebApp.api.services
{
    public partial class LegacyWebForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
...
webworm
  • 10,587
  • 33
  • 120
  • 217
  • Should be valid, you're not missing runats? –  May 10 '19 at 21:49
  • I do have `runat="server"` on the containing `
    ` element and all the controls
    – webworm May 10 '19 at 21:52
  • Is it registered in your `.aspx.designer.cs`? (`protected global::System.Web.UI.WebControls.TextBox someTextBox;`, and does that file have the correct namespace? –  May 10 '19 at 22:10
  • That I am not sure off. I did not use the designer when I created it. Do you know where this file is located? The only files I moved over where the ASPX file and it's code-behind – webworm May 10 '19 at 22:12
  • 1
    [Designer](https://stackoverflow.com/questions/3284710/aspx-designer-cs-how-does-it-work) It will be adjacent in the file hierarchy with the `.aspx.cs` code behind file [regenerating the designer](https://web.archive.org/web/20100328053551/http://www.undermyhat.org/blog/2009/07/tip-regenerate-aspx-designer-cs-files-when-corrupted/) –  May 10 '19 at 22:21
  • 1
    @UK_Dev - That did it! The link you provided to [Designer](https://stackoverflow.com/questions/3284710/aspx-designer-cs-how-does-it-work) had all the instructions to regenerate the .aspx.designer.cs file. After that It compiled and ran. Thanks soo much! FYI - The answer from `David-Dietrich` contained the steps I followed. – webworm May 10 '19 at 22:39
  • Unfortunately it's something that you only discover after scratching your head for a while - glad to have helped. –  May 10 '19 at 22:54

1 Answers1

1

It looks like you're missing a designer file.

.aspx.designer.cs

This highlights the usage of a designer.

You can regenerate a designer file.

You may need to clean the project and rebuild it if the desiger file is still throwing missing references when you try to compile it.