欢迎光临
我们一直在努力

ASP.NET 2.0 new features-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

 

from quickstart:

simplified code behind model new in 2.0

asp.net 2.0 introduces an improved runtime for code-behind pages that simplifies the connections between the page and code. in this new code-behind model, the page is declared as a partial class, which enables both the page and code files to be compiled into a single class at runtime. the page code refers to the code-behind file in the codefile attribute of the <%@ page %> directive, specifying the class name in the inherits attribute. note that members of the code behind class must be either public or protected (they cannot be private).

c# codebehind code separation
 
the advantage of the simplified code-behind model over previous versions is that you do not need to maintain separate declarations of server control variables in the code-behind class. using partial classes (new in 2.0) allows the server control ids of the aspx page to be accessed directly in the code-behind file. this greatly simplifies the maintenance of code-behind pages.

这对开发来说确实是一个改进,codebehind中去掉server control的声明会使代码”清爽”很多,看起来舒服多了。请看示例:

这对开发来说确实是一个改进,codebehind中去掉server control的声明会使代码”清爽”很多,看起来舒服多了。请看示例:

页面中我们放置一个textbox:
test.aspx
<%@ page language=”c#” codefile=”test.aspx.cs” inherits=”test_aspx” %>

<html>
<head>
    <title>test asp.net 2.0</title>
</head>
<body>
    <form runat=”server”>
      <asp:textbox id=”textbox1″ runat=”server”/>
      <asp:button id=”button1″ text=”click me” onclick=”button1_click” runat=”server”/>
      <br />
      <br />
    </form>
</body>
</html>

test.aspx.cs
using system;

public partial class test_aspx: system.web.ui.page
{
    protected void button1_click(object sender, eventargs e)
    {
        response.write ( “hi,you have entered the word: ” + textbox1.text);
    }

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP.NET 2.0 new features-.NET教程,Asp.Net开发
分享到: 更多 (0)

相关推荐

  • 暂无文章