Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.


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

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");

In my case, I was working with some old web site code, which I converted to a VS2008 solution. I encountered this same problem.

For me, the fix was to right-click the Web Sites project in the Solution Explorer and select Convert to Web Application. This created designer.cs files for all pages, which did not yet have these files before.


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