简体   繁体   中英

asp.net code-behind doesn't see an object declared in aspx page and causes build error

Strange situation, one of my panels declared in ASPX file is not seen in code-behind. It causes build errors. So, there are two questions here:

1) I have an asp:Panel pnlList in ASPX file. I try to add a control to it in code-behind, but .NET underlines it with blue line and says that the panel does not exist. So, build errors occur. But when I just run a page without building application, this page works fine. See code samples:

ASPX :

<div style="position: absolute; top: 25px; left: 515px; width: 403px; height: 187px; overflow-y: scroll; overflow-x: hidden;">
    <asp:Panel ID="pnlList" runat="server" Style="position: absolute; top: 0px; left: 0px; width: 400px;" EnableViewState="False">
    </asp:Panel>
</div>

ASPX.CS :

pnlList.Controls.Add(pnlItem);

2) How to make Visual Studio see and highlight syntax in ASPX pages? It doesn't highlight it at all and moreover, it doesn't autocomplete my code in code-behind when I start typing a name of any object declared in ASPX page.

如果您使用的是Web应用程序,或者在aspx页面上使用.designer.cs文件,现在大多数情况下Visual Studio会自动生成面板,因此您需要确保将面板添加到设计器文件中。在某些情况下,手动键入无害。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM