Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Control not available in CodeBehind

I drag and drop a Label control on my ABC.ASPX page.It Compiles correctly. But the control (Label2) is not available in code-behind ABC.ASPX.cs for value assignment.

What is the resolution?

<%@ Page language="c#" CodeBehind="ABC.aspx.cs" AutoEventWireup="false" %> 

 <asp:Label ID="Label2" runat="server" Font-Bold="True"></asp:Label>
like image 313
GilliVilla Avatar asked Apr 09 '12 22:04

GilliVilla


2 Answers

You are probably missing an entry for this in your designer.cs file. You can either add something like this to the file:

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

Or delete the designer.cs file, right click the parent aspx file and choose "Convert to Web Application". This should recreate the designer.cs file with all the appropriate entries.

like image 138
Abe Miessler Avatar answered Sep 28 '22 09:09

Abe Miessler


You might need to add Inherits="XXX.ABC" in your Page Directive, where XXX is your root namespace. Also, I'm assuming that you named your class ABC to coincide with ABC.aspx.cs.

like image 32
Code Maverick Avatar answered Sep 28 '22 09:09

Code Maverick