Shyju
Shyju

Reputation: 218702

ASP.NET Controls are not coming in Code-behind IntelliSense

I am having an aspx page where I have added one asp.net text box control with ID and RUNAT attribute. But in Code-behind I am not seeing this control's name in the intellisense.

My page directive in aspx is as follows

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MyProject_UI._Default" %>

I am using VS 2008. Any idea how to get rid of this?

Upvotes: 2

Views: 3465

Answers (3)

vikingben
vikingben

Reputation: 1652

This will happen if you are trying to include your control in LayoutTemplate. For example if you are using an asp label in a login control you have converted to a LayoutTemplate.

<asp:Login ID="userLogin" runat="server">
   <LayoutTemplate>
     <!--Username and password controls-->
     <asp:Button ID="btnLogin" CommandName="Login" runat="server" Text="Login" />
     <asp:Label ID="lblAlert" runat="server"></asp:Label>
   </LayoutTemplate>

So your lblAlert will not show up on the code behind take it out of the layouttemplate or use a loop to find the control within the layout object.

var mylabel = (Label)userLogin.FindControl("lblAlert");

Upvotes: 2

RickNZ
RickNZ

Reputation: 18654

Try using CodeFile instead of CodeBehind. The latter is a hold-over from .NET 1.1.

Also, make sure the namespaces match up between the markup and the code. Do a test compile to be sure.

Upvotes: 4

Gabriel McAdams
Gabriel McAdams

Reputation: 58253

I have seen this on occasion when I edit a page. When it happens to me, I close the files and open them again and it seems to fix itself.

Upvotes: 3

Related Questions