【问题标题】:ASP.NET Controls are not coming in Code-behind IntelliSenseASP.NET 控件未出现在代码隐藏 IntelliSense 中
【发布时间】:2009-12-23 05:53:13
【问题描述】:

我有一个 aspx 页面,我在其中添加了一个带有 ID 和 RUNAT 属性的 asp.net 文本框控件。但在代码隐藏中,我没有在智能感知中看到此控件的名称。

我在aspx中的页面指令如下

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

我正在使用 VS 2008。知道如何摆脱这个问题吗?

【问题讨论】:

    标签: asp.net visual-studio-2008 intellisense code-behind


    【解决方案1】:

    尝试使用CodeFile 而不是CodeBehind。后者是 .NET 1.1 的延续。

    此外,请确保标记和代码之间的命名空间匹配。做一个测试编译以确保。

    【讨论】:

      【解决方案2】:

      我在编辑页面时有时会看到这种情况。当它发生在我身上时,我关闭文件并再次打开它们,它似乎会自行修复。

      【讨论】:

        【解决方案3】:

        如果您尝试将控件包含在 LayoutTemplate 中,就会发生这种情况。例如,如果您在登录控件中使用 asp 标签,则您已转换为 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>
        

        因此,您的 lblAlert 不会显示在后面的代码中,将其从布局模板中取出或使用循环在布局对象中查找控件。

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

        【讨论】:

          猜你喜欢
          • 2015-02-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-07-10
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多