Control does not exist in the current context

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cbellew
    New Member
    • Sep 2007
    • 26

    Control does not exist in the current context

    G'day,

    I have encontered what appears to be a common problem, but unfortunately the typical solution i have found has not worked for me.

    I have just copied the files from an "ASP .NET Web Site" to an "ASP .NET Web Application" because i have learned about the differences and have decided to move to the latter. I simply copied and pasted all the .aspx (with respective .aspx.cs code-behind files) and some other files such as scripts etc into the "Web Application". I have also added the same references to class libraries I had in the "Web Site".

    When I come to compile the "Web Application", I get errors saying that controls "cannot be found in the current context". I did not get these errors in the "Web Site" and the common problem apparently is that there are backup files or duplicate partial classes, which i'm certain is not the case for me...

    One example is that I have an ASP:PlaceHolder in header.aspx as follows...

    <asp:Placeholde r runat="server" ID="headermenuh older">

    ...but i get the error "The name 'headermenuhold er' does not exist in the current context"

    I would be VERY greatful if someone could give me their opinion! :)

    Best Regards,
    Chris
  • cbellew
    New Member
    • Sep 2007
    • 26

    #2
    Sorted.

    Turned out i wasn't aware that in "ASP .NET Web Application" projects there needed to be both .cs and .designer for each page. I created a new page by going to add item and the correct .designer page was created, so i copied the code from the old version, deleted the old version and recompiled and it worked!

    Thanks anyway :)

    Comment

    • cbellew
      New Member
      • Sep 2007
      • 26

      #3
      Even Better!

      Right click on the file and choose "Convert to Web Application" - feel a bit silly now!

      Thanks

      Comment

      • praveenb000
        New Member
        • Aug 2008
        • 21

        #4
        ok, u got it, and nice to share with us

        Comment

        • rathinakumarb
          New Member
          • Nov 2009
          • 1

          #5
          Even silly things are great for unknown like me ... Thanks a lot .. I too had probelm in converting the website to web project

          Thanks to cebellew !!!

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            It's good to know how you solved your solution.
            I didn't realize that you can see this error in the case when the .designer file is missing (normally this file isn't missing because it's typically automatically generated for you by Visual Studio....I can see how it would be a problem if it were missing).

            Usually when this type of error shows up someone is trying to use something that they aren't allowed to use in the Global.asax file.

            Well, at least that's when I encountered this error.

            The Global.asax file is a tricky thing. In some methods things like Session are available and then in other methods it is not. It's a little confusing when you first start using the Global.asax but once you realize what it's for things start making sense.

            -Frinny

            Comment

            • Pano

              #7
              HA! hours of messing about was driving me to drink. literally.

              Rightclick project, convert to web application.

              Done deal.

              Thanks cbellew.

              Comment

              Working...