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

前端 未结 16 1322
面向向阳花
面向向阳花 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:39

    Check out your aspx file on errors, once I've faced with that problem

    0 讨论(0)
  • 2020-12-25 12:42

    you will also find .net temp files which are safe to delete here: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

    0 讨论(0)
  • 2020-12-25 12:44

    FYI...I was having this problem too and I ended up fixing it by deleting the existing .designer.vb file, right-clicking on the project and choosing Convert to Web Application. It then showed the real "error" that was causing the GUI to crap itself. Turned out I had used the same name for 2 other labels but that wasn't being shown in the error list window. Once I renamed one of the 2 other labels it built fine and stopped giving me trouble.

    0 讨论(0)
  • 2020-12-25 12:48

    The above fix (deleting the temp files) did not work for me. I had to delete the PageName.aspx.designer.cs file, then right-click my page, and choose "Convert to Web Application" from the context menu.

    When Visual Studio attempted to rebuild the designer file, it encountered (and revealed to me) the source of the problem. In my case, VS had lost a reference to a DLL needed by one of the controls on my page, so I had to clean out the generated bin folders in my project.

    0 讨论(0)
  • 2020-12-25 12:48

    Just to add my two cents with this problem.

    The only thing from all the above that worked for me was the "Clean" and then delete anything left in the bin folder. Rebuild and all controls started working then.

    0 讨论(0)
  • 2020-12-25 12:50

    Is the control that you are trying to reference inside of the repeater?

    If so then you need to look them up using the FindControl method.

    For example for:

    <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <asp:LinkButton ID="LinkButton1" runat="server">stest</asp:LinkButton>
        </ItemTemplate>
    </asp:Repeater>
    

    You would need to do this to reference it:

    LinkButton lb = Repeater1.FindControl("LinkButton1");
    
    0 讨论(0)
提交回复
热议问题