0

So I'm attempting to convert a website project to a web application project. I created the new web application project, moved over the files, created and populated the designer files for each ASPX and ASCX file, and included those files. Once done I ran through and corrected some smaller things here and there but all is good... except a few user controls.

So I have user controls with things like <%=Message %> in them which corresponds to a public property in the code behind class. Visual Studio now says "The name 'Message' does not exist in the current context." I've tried everything from making a new control and retyping the code to trying the newer <%: shorthand tag. Nothing seems to allow VS to "see" the property.

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DoubleHrBanner.ascx.cs" Inherits="Test.ctrl.misc.DoubleHrBanner" %>

<hr class="faded" />
<span><%=Message %></span>
<hr class="faded"  />

and

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Test.ctrl.misc
{
  public partial class DoubleHrBanner : System.Web.UI.UserControl
  {
    public string Message = "";
    public int Count = 0;
  }
}
Licht
  • 1,079
  • 1
  • 12
  • 27
  • Is the code in your code-behind being compiled? – Andrew Barber Nov 14 '14 at 21:41
  • Build action is set to compile. Project as a whole doesn't compile right now because of errors in the ASCX files stemming from this issue. So I can't tell you if it works-works. – Licht Nov 14 '14 at 21:51
  • Hmmm... an ASCX file should not generally be part of the compilation. ASCX/ASPX files are only compiled on first run. – Andrew Barber Nov 14 '14 at 21:52
  • Wouldn't that be true of the website project type I came from and not the web application project type I'm going to? (Web apps get compiled into a single DLL at build which IIS loads into memory and runs. Or that's my understanding.) Additionally I'm working with a new Usercontrol file, not one I moved over. I'd hope the default settings would be correct. Maybe I messed them up somehow but I haven't monkeyed around too much. – Licht Nov 14 '14 at 21:54
  • Nope; it's a separate thing to pre-compile the pages/controls. I always use Web Apps, and have historically dealt with odd things due to the disconnect; like renaming something, compiling, but then realizing I'd not renamed it in the ASPX, too. The app still compiles, but when loading page(s) involved, you get a compilation error from the web server – Andrew Barber Nov 14 '14 at 21:56
  • Another thing I would like to add is that in this conversion I was unable to use "Convert to web app" in the solution tree... As it wasn't there. Googled all over and found no solutions for it being missing. Thus I wrote a console application and some elbow grease to handle the task. – Licht Nov 14 '14 at 22:02
  • Ahh... there might be something there causing the problem. If you need to do it "manually", you might want to start with a blank web app, and add your code in from there. – Andrew Barber Nov 14 '14 at 22:03

1 Answers1

1

I forgot to update this quite some time ago. So for anyone facing a similar situation I would give you two bits of information.

  1. If you're looking for the Convert To Web Application button in VS2013, it's been moved from the context menu. Select your item to convert in the Solution Explorer and then click Project>Convert To Web Application at the top of VS.

  2. If you have >300 compiler errors following the conversion and VS is throwing a huge fit about inline code, just ignore it. Fix all other errors first and once all the code behind and dependent code behind (such as user controls inside user controls) and VS will eventually get itself together and stop throwing errors on your inline code for no reason.

Licht
  • 1,079
  • 1
  • 12
  • 27
  • I have been facing this issue for months and I still cannot figure out how to get rid of the errors. The only errors I have are the ones you had. – Justin Dec 15 '15 at 14:50
  • 1: Try removing any inline code. 2: Make sure the full namespace and class name is specified when specifying the code behind files for ASPX files throwing the error. – Licht Dec 16 '15 at 14:09
  • The inline code is the very thing I want for such things as `<%# showEdit() %>` for example. It is throwing the error but still compiling and running. Removing that isn't really a fix. – Justin Dec 29 '15 at 18:12