Accessing controls of .aspx file in .aspx.cs without any declaration.!!??

Posted on Microsoft .NET Support Team See other posts from Microsoft .NET Support Team
Published on Wed, 10 Feb 2010 08:12:00 +0000 Indexed on 2010/03/16 15:31 UTC
Read the original article Hit count: 218

Filed under:

I am able to access the controls of ".aspx" file in ".aspx.cs" directly without any declaration in ".aspx.cs" or in designer.cs. How is this possible? This is happeing only if I open website as using File System.

  1. Create a new ASP.NET web site application with Visual Studio 2008.
  2. So following three files will be created automatically
                 "Default.aspx",
                 "Default.aspx.cs"
                 "Default.designer.cs"
  3. Now Delete "Default.designer.cs" perminently.
  4. Just create a button in Default.aspx file
       <asp:Button runat="server" Text="Save Plan" ID="btnSave" />  
  5. Close the Solution and open the website as File System.              
    File -> Open Web Site -> File System -> Select Web Site Folder and Open the project.                  
  6. Now btnSave is automatically recognized in Default.aspx.cs without any declaration in Default.aspx.cs as bellow

                           System.Web.UI.WebControls.Button btnSave;

How btnSave is being recognized by .cs file without defining it anywhere as an object of System.Web.UI.WebControls.Button?

Note: This happens only if you open Web Site from File System.
          and No Declaration at all for btnSave.

Please refer this article on this.

© Microsoft .NET Support Team or respective owner

Related posts about ASP.NET