does not contain a definition for 'Form1' and no extension method 'Form1'

12,228

Couple of things to think about:

1) Are you getting this error when building the site, in a development tool like Visual Studio, for example? If you are, then take a look at the Page element at the top of the ASPX code:


    <%@ Page Language="C#" %>

And make sure the inherits, source file and other attribuets are all pointing at the right class name, .cs file in the code behind. ALso check the designer.cs file for your page to make sure the Form1 property is declared.

2) If you are getting this when deploying the site and visiting it, then it's likely that you haevn't deployed the site dll's to the bin folder correctly. If it's a website project then it creates a dll per page, and you must make sure the latest version is deployed.

Posting the ASPX, and cs and designer.cs files would be useful, but some more detail about when you are seeing the error would be helpful too.

Share:
12,228
Alexxx
Author by

Alexxx

Updated on June 04, 2022

Comments

  • Alexxx
    Alexxx almost 2 years

    Compiler Error Message: CS1061: 'ASP.admin_users_aspx' does not contain a definition for 'Form1' and no extension method 'Form1' accepting a first argument of type 'ASP.admin_users_aspx' could be found (are you missing a using directive or an assembly reference?)

    Line 317:            #line default
    Line 318:            #line hidden
    Line 319:            this.Form1 = @__ctrl;
    Line 320:            
    Line 321:            #line 168 "C:\Users\SIMiP1\Desktop\BON\CellularOrders.Presentation.Web\Admin\Users.aspx"
    

    I don't understand this error and what might be the reason for this error Please tell me what do you understand from this error msg and what CODE I would need to post here - cause the users.aspx file is long and has 222lines

    this is line 168:

       <form id="Form1" runat="server">
            <CellularOrders:Menu ID="Menu1" runat="server" />
            <div class="Main">
                <table>
    
  • Alexxx
    Alexxx over 12 years
    I am using visual studio - i dont have thus error while debuging or building the project - i have this only when i am entering the page on the browser
  • Alexxx
    Alexxx over 12 years
    on the designer.cs i have: protected global::System.Web.UI.HtmlControls.HtmlForm Form1;
  • Alexxx
    Alexxx over 12 years
    about deploing the dll-i just BUILD > PUBLISH do i need to do something else with the dlls?
  • Alexxx
    Alexxx over 12 years
    i get the error only on visiting the page...no error on build or debug.
  • dash
    dash over 12 years
    Also, look at the published files. In the files you have published, locate the original page. In the Page Element, it will point at the DLL where the code for the page is stored. The name will probably be something like .admin_users_aspx_13489jsdhk.dll. Then check this dll is in the bin folder too.If you are building a web application project, then there will be only one dll for the whole website (with all the code behind classes inside). In this instance, check that the right version is in the bin folder on the site you've deployed.