Just curious!
I was wondering, what actually happens so that any control that is defined in .aspx page and having "runat" attribute is accessible in code behind file?
.aspx page:
code behind page: lbl.Text = "This is a label";
If anyone can share some information about what actually is happening here, what makes my label accessible in code behind after adding "runat" attribute?
Every time you change your
aspxfile Visual Studio will regenerate a file named {YourPageName}.aspx.designer.cs and declare controls with attribute runat="server" in it.So if you have a label control in your
aspxfile like this:then there is a variable declared in your
.aspx.designer.csfile which is auto generated like this:Since your page is declared as a partial class you can access
lblin code behind file.You can open the file and take a look at its content.