The code page cannot "see" any elements / controls declared on the aspx page

Here is my Default.aspx page (with unnecessary details):

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div id="login"> <!-- a bunch of markup has been removed, so this html will appear wrong and not valid, but it actually is --> <table align="center" width="80%" cellpadding="0" cellspacing="0" class="loginBg"> <tr> <td colspan="2"><img src="images/Login_top.jpg" /></td> </tr> <asp:Panel runat="server" ID="pnlLoginIn"> <tr> <td style="padding-left:20px;">Username</td> <td style="padding-right:15px;" align="right"><asp:TextBox id="txtUsername" runat="server" /></td> <asp:RequiredFieldValidator runat="server" ID="rfvUserName" ErrorMessage="*" ControlToValidate="txtUsername" ValidationGroup="credentials" Display="Dynamic" /> </tr> <tr> <td style="padding-left:20px;">Password</td> <td style="padding-right:15px;" align="right"><asp:TextBox ID="txtPassword" TextMode="Password" runat="server" /></td> <asp:RequiredFieldValidator runat="server" ID="rfvPassword" ErrorMessage="*" ControlToValidate="txtPassword" ValidationGroup="credentials" Display="Dynamic" /> </tr> <!-- BUT THE PANEL IS HERE?! --> <asp:Panel ID="pnlInvalidCredentials" runat="server"> <tr> <td colspan="2" align="center" style="color: Red;"><asp:Literal runat="server" ID="litInvalidCredentials" Text="Invalid Username or Password" /> </td> </tr> </asp:Panel> <!-- more code has been removed down here...I just left the block commented in where the pnlInvalidCredential lives --> </asp:Content> 

Here's the code behind (with unnecessary details cut out):

 namespace webapp { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { (webapp.MasterPages.MasterPage)Page.Master).headerImage = "default"; this.Master.headerImage = "default"; if (!Page.IsPostBack) { this.pnlInvalidCredentials.Visible = false; // error is here this.BindPressRoomItem(); } } } } 

This top-level page / code is not a folder or anything else. Also, this project is an ASP.NET web application that borrows code from an old website project. I did not add “Existing” to any files, all files were “Add New” to prevent compatibility issues. I tried this one , it didn’t work.

In code, each attempt to manipulate elements declared on an aspx page results in an error, for example:

'_ Default' does not contain a definition for 'pnlInvalidCredentials'

or

In this context, the name 'txtUsername' does not exist.

+4
source share
4 answers

Since I updated this page, you deleted the line with the page directive at the top of your html file, but it looks like you might need to include a namespace.

Try:

Inherits = "webapp._Default" instead of Inherits = "_ Default"

+4
source

Try changing the "CodeBehind" attribute on the Default.aspx page to "CodeFile".

+3
source

If this is a web application, sometimes it happens that the * .designer.cs file is not updated with the latest changes.

Try the following:

  • Remove the panel (just cut it)
  • Save
  • Cancel
  • Save again (this will restore the * .designer.cs file)
  • Rebuild

Edit:

Other features that the * .designer.cs file cannot recover are syntax errors, such as missing end tags in your aspx pages.

+1
source

I had the same problem. For me this has been fixed:

  • in my code behind the file, the class was defined as an "Open class". Changing this to "Partial Class", then clicking "Convert to Web Application", he restored the "Designer" file and fixed the problem.
0
source

Source: https://habr.com/ru/post/1396468/


All Articles