Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Wednesday, February 10, 2010

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

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
  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.

Post a Comment