5

Here's a my Default.aspx page (with unnecessary details excised):

    <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 excised):

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 page/code-behind is top level, it's not it any folder or anything. Also this project is an ASP.NET Web Application that is borrowing code from a legacy web site project. I didn't "Add Existing" to any files, all files were "Add New" to prevent compatibility problems. Tried this, didn't work.

In the code-behind, every attempt to manipulate items declared in the aspx page results in an error like:

'_Default' does not contain a definition for 'pnlInvalidCredentials'

or

The name 'txtUsername' does not exist in this context.

Community
  • 1
  • 1
kmarks2
  • 4,755
  • 10
  • 48
  • 77
  • 2
    do you need an ending tag by the way.. not that that will fix your problem but looking at being consistent can you paste in the header of the page as well I want to see what <%@ Page Language="C#" CodeFile=" " Inherits=" " %> looks like – MethodMan Feb 14 '12 at 18:52
  • Hey thanks. Yeah I removed code that wasn't necessary to the example, and accidentally took out the closing
    with it.
    – kmarks2 Feb 14 '12 at 18:58
  • 1
    Is this a web site project or web app project? – abatishchev Feb 14 '12 at 18:58
  • 2
    Your HTML is **absolutely** incorrect. Your VS should **yield** about that. – abatishchev Feb 14 '12 at 18:59
  • Web app project. Also I chopped a bunch of the html out to make this example more brief. It validates find...everywhere you see "..." in markup a bunch of code is removed. – kmarks2 Feb 14 '12 at 19:15
  • 1
    @kmarks2: Even considering removed code, it's still incorrect. You can't put anything between `` and ``, etc. – abatishchev Feb 14 '12 at 19:25
  • @abatishchev Thanks. Not sure how I missed that. – kmarks2 Feb 14 '12 at 20:18

4 Answers4

4

Since I refreshed this page you've removed the line with the page directive at the top of your html file, but it looked like you maybe need to include the namespace.

Try:

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

Eden
  • 523
  • 1
  • 7
  • 21
  • Thanks for the tip. I had already tried this and it didn't work. Then I just tried it again and it solved all my problems. I'm wondering why things (I'm using VS2010) are so very inconsistent when dealing with legacy pieces of code. – kmarks2 Feb 14 '12 at 19:13
3

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

Tim S. Van Haren
  • 8,861
  • 2
  • 30
  • 34
  • 1
    Thanks for the tip. Unfortunately this did not work. Everything just seems so hacky with ASP.NET...why is getting a page and it's code-behind linked so hard, I mean these files were generated by VS. – kmarks2 Feb 14 '12 at 18:52
  • 1
    if the old .aspx page were done in .net 1.1 then changing to CodeFile would work.. question is .. what version was the old page done in.. also have you tried accessing the pnlInvalidCredentials without using the this.pnlInvalidCredentials – MethodMan Feb 14 '12 at 18:56
  • @DJKRAZE It's possible. It's an old project that was originally done in VS2008 but that's all I know. The original dev is long gone. When you say "accessing pnlInvalidCredentials without using this.pnlInvalidCredentials" what do you mean? What other way is there to access this in the code-behind? Thanks a million. – kmarks2 Feb 14 '12 at 19:00
  • if you were to add using HTML.Controls you could access it just by its name but sounds like Lngenu had a correct fix for you.. – MethodMan Feb 14 '12 at 19:03
1

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

Try this:

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

Edit:

Other possibilities that will fail the regeneration of the *.designer.cs file are syntax errors such as missing end tags in your aspx pages.

Candide
  • 30,469
  • 8
  • 53
  • 60
  • 1
    I wonder if you a syntax error, such as a missing ending tag. That will fail the build of the designer.cs too. – Candide Feb 14 '12 at 18:59
  • It's possible. I've corrected all validation related warnings except little things like " 'img' is missing required attr 'alt' ". – kmarks2 Feb 14 '12 at 19:01
  • 1
    Somethings, I'm noticing. the asp:RequiredFieldValidator is within tr tags. Try moving it inside td tags. Also, the first table doesn't end, and neither does the first Panel. – Candide Feb 14 '12 at 19:08
0

I just had the same problem. What fixed it for me was:

  • in my code behind file, the class was defined as 'Public class'. Changing this to 'Partial Class', then clicking 'Convert to Web Application' regenerated the 'Designer' file and fixed the problem.
TonyC
  • 41
  • 4