开发者

.aspx vs .cs class

开发者 https://www.devze.com 2023-01-27 11:53 出处:网络
what is 开发者_StackOverflow社区the difference between the .aspx class and the .cs class of appcode?

what is 开发者_StackOverflow社区the difference between the .aspx class and the .cs class of appcode?

when i write some aspx class it's aspx.cs by default inherit the System.Web.UI.Page and it's aspx paeg in page directive mention the tag inherit="page_name_what we saved with", cant we make it inherit something else like .cs class of appcode, all this confuse me please elaborate me on this.


The aspx file contains your page markup. It's automatically converted into code by ASP.NET.

The cs file contains the code behind your page (initialization, event handlers, etc.). You have to write that code yourself.

EDIT: The Inherits attribute of the @ Page directive associates the page markup to the code behind: when compiling the page, ASP.NET converts the markup into a class that actually inherits from the code-behind class, e.g. something like:

class __Generated_YourPage : YourPage
{
}

That's why the autowired event handlers in your code behind (e.g. Page_Load) have to be protected and not private.

You can change that attribute, but you have to change the name of the class in your code-behind file accordingly, or the code generated from the markup won't compile because it won't find the class it's supposed to inherit.

0

精彩评论

暂无评论...
验证码 换一张
取 消