1

I cannot access my UI controls on my ASP.Net website.

When I create a brand new form and drag a control on it, I can use C# to change the properties of the control easily, like one would expect.

But when I try to do the same on another page, I cannot access any control whether I drag a new control on the page or not.

It seems the code behind and the visual page aren't connected.

How can I fix this?

3
  • Are you using a web site project or a web application project. If using a web app project, try deleting the .designer.cs file, right clicking on the aspx file and selecting Convert To Web Application. Commented Aug 31, 2010 at 23:50
  • i.imgur.com/TPTPF.jpg - Idon't have a designer.cs file - Any other suggestions. I'm desperate. Commented Aug 31, 2010 at 23:53
  • The screenshot doesn't communicate which web project type you are using; however, it appears you are using a web site project. The best I can think of is to check the <%@ Page %> directive. Ensure the proper code behind is specified, and ensure that no assembly name is specified. Good luck! Commented Aug 31, 2010 at 23:59

3 Answers 3

4

off the top of my head:

Is the code behind file registered in the top line of the ASPX file?

<%@ Page Title="Title" Language="C#" MasterPageFile="~/Default.Master" AutoEventWireup="true"
    CodeBehind="Page.aspx.cs" Inherits="MyNameSpace.Page" %>

Has the designer file been deleted, or otherwise corrupted? if so try deleting the deigner file. VS should regenerate it for you.

Check the build action on the designer/code behind files and make sure that they are both set to 'Compile' (you can change this setting by right-clicking on the files in VS and seleting properties, build action should be in the file properties editor)

Make sure your project file is set up correctly. sometimes going through a project file upgrade (like when you change VS versions) or simply sharing project files through a source contorl system can cause things to get out of whack. confirm that for your files you have entries that look like this in your csproj file (confirm with a text editor, notepad is fine):

<Compile Include="Page.aspx.cs">
  <DependentUpon>Page.aspx</DependentUpon>
  <SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Page.aspx.designer.cs">
  <DependentUpon>Page.aspx</DependentUpon>
</Compile>

I hope one of these solves your problem!

Sign up to request clarification or add additional context in comments.

Comments

0

If you don't have a designer.cs file, just right-click on the aspx and "Convert to Web Application" and then you'll get one.

Comments

0

I know this is an old question, but seeing as I have encountered the same issue when creating an aspx page without a designer file, I felt it was necessary to share my solution to the problem.

In order to use ASP controls present on a page, you need to do is declare the control as a field within the class, that is, the class associated with the 'Inherits' attribute in your page. For example, if I have a label control on my page with an ID of 'test', then I would declare the following in my class:

protected System.Web.UI.WebControls.Label test;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.