ASP.NET controls cannot be referenced in code-behind in Visual Studio 2008

前端 未结 16 1323
面向向阳花
面向向阳花 2020-12-25 12:28

Ok, so, my visual studio is broken. I say this NOT prematurely, as it was my first response to see where I had messed up in my code. When I add controls to the page I can\'t

相关标签:
16条回答
  • 2020-12-25 12:52

    This can also happen if the Inherits property on the source page doesn't match the class name in the code behind. Generally speaking, this would probably only happen if you copy/pasted a .ascx/.aspx file and forgot to update it.

    Example:

    <%@ Control AutoEventWireup="false" CodeBehind="myControl.ascx.vb" Inherits="myProject.myWrongControl" %>
    

    The the code behind class:

    Partial Public Class myControl
    
    0 讨论(0)
  • 2020-12-25 12:56

    try clearing your local VS cache. find your project and delete the folder. the folder is created by VS for what reason I honestly don't understand. but I've had several occasions where clearing it and doing a re-build fixes things... hope this is all that you need as well.

    here

    %Temp%\VWDWebCache
    

    and possibly here

    %LocalAppData%\Microsoft\WebsiteCache
    
    0 讨论(0)
  • 2020-12-25 12:57

    right click on project name and select "Clean". then, check your bin folder if it has any dll remaining. if so, delete it. that´s it. just rebuild and every thing will work fine.

    0 讨论(0)
  • 2020-12-25 13:01

    You have to add

    runat="server"
    

    to each element in your page.

    0 讨论(0)
提交回复
热议问题