Question

There are quite a few questions out there regarding this (for me, recurring) issue, but none of them have solved my problem.

Problem:

Whatever control I add in my aspx page, it is not recognised in the codebehind. Compiling doesn't work, because the ID is not recognised.

None of the following worked:

  • Clean and rebuild solution.
  • Close and open VS
  • Delete asp.net temp files
  • Check project's target framework.
  • Check assemblies are all there.
  • Check designer viewn to see if the control is actually there (it is)
  • Get control's ID with JS function to check it is the intended one (it is)

The problem has started only recently. In fact, I can reference the older controls fine. The problem is observed both with standard ASP controls and Telerik ones.

Does anyone know of something else I should try? Please help me, I'm in the middle of a project and this is causing unnecessary delays, ta.

Was it helpful?

Solution 2

This is how I solved my issue. For a full account of it, please refer to the comments above.

  1. I've noticed that although my project was already of web application type, designer files weren't showing.
  2. I've forced the designer files to be recompiled by clicking on the ''convert to web application' option

I was then able to reference the control ID.

Thanks to the commentators anyway.

OTHER TIPS

Make sure all of your asp.net controls (in the .aspx file) have the:

runat='server'

tag... Without this, you will not be able to reference the controls.

e.g.

<asp:Label runat='server' Text='Test Label' ID='TestLabel' />

Hope this helped...

Rodit

I was having a similar issue, due to the fact that I was using the pre-generated Login page. My solution was to change this section from this:

<asp:Login runat="server" ViewStateMode="Disabled"   RenderOuterTable="false">
<LayoutTemplate>

To this:

<asp:Login ID="asplogin" runat="server" ViewStateMode="Disabled" RenderOuterTable="false">
<LayoutTemplate>

basically, I just added an ID to the asp:Login which allowed me to access the objects in the code from behind by prefixing the control name with asplogin

asplogin.youControlNameHere

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top