Question

I know that there's always been issues with declaring server-side controls directly in HTML in Visual Studio. Usually, you have to open the page in design mode in order to get them generated in code behind so you can access via your code. But I do have a strange issue here. I added a asp:Label control on a page that inherits a master page.

<asp:Label ID="uxEnteteresultat" runat="server" Text="Test"></asp:Label>

These pages use a framework named Ext.Net that generates Ext.js code. My designer simply doesn't work, so there's no way I can get this control generated in the codebehind file.

And where are those controls declared ??? In older version of .Net (I'm in VS 2010 using 4.0 framework), we could see it in a partial class. Where are they now ? Is there a workaround to declare your control yourself in VS 2010 ?

Thanks !


There is no designer.cs files at all. It is a website, not a project. That might be a part of the problem...

No correct solution

OTHER TIPS

In VS 2010 each Form should have three parts:

  • MyForm.aspx
  • MyForm.aspx.cs
  • MyForm.aspx.designer.cs

You should be able to add a Label like so:

Add this to MyForm.aspx:

<asp:Label ID="lblOrganizer" runat="server" /> 

Add this to MyForm.aspx.designer.cs (within public partial class):

protected global::System.Web.UI.WebControls.Label lblOrganizer;

Controls declared inside mypage.aspx page are created in a partial class inside mypage.aspx.designer.cs

/// <summary>
/// uxEnteteresultat control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label uxEnteteresultat;

If your controls are not declared in this file will not appear in codebehind mypage.aspx.cs. Remember that all controls should have the property runat = "server" in its declaration in HTML.

Check this similar question:

Asp.net controls are not accessible in code behind

If you're getting intellisense then you're fine because you shouldn't have to explicitly declare your controls in the code-behind since ASP.NET 2.0 (partial classes). If you can't access it, check your designer file and manually add it there per user1694951.

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