当前位置:首页 > 网络编程 > WEB编程 > ASP.net > 细细品味ASP.NET (三)

细细品味ASP.NET (三)

点击次数:23 次 发布日期:2008-11-26 23:28:56 作者:源代码网
源代码网推荐 页面事件
源代码网推荐
源代码网推荐 在此前我提到 ASP.NET已经被从头到脚地重写了,但是我并没有指出它是按照面向对象的思路重建的。在对象树的顶部是Page对象,即页面对象,ASP.NET的每个控件、应用程序和页面都是从这个对象中继承来的,也就是说每个页面都是页面对象的一个例示。页面的Load (装载)事件是一个非常重要的事件,如下面的表3代码所示:
源代码网推荐 表3 使用页面事件
源代码网推荐 <html>
源代码网推荐 <s cript language=“VB” runat=“server”>
源代码网推荐 Sub Page_Load(Source As Object, E As EventArgs)
源代码网推荐 ‘ code to run when page loads
源代码网推荐 End Sub
源代码网推荐 Sub SubmitButton_Click(Source As Object, E As EventArgs)
源代码网推荐 ‘ code to run when button is clicked
源代码网推荐 End Sub
源代码网推荐 Sub Page_Unload(Source As Object, E As EventArgs)
源代码网推荐 ‘ code to run when page unloads
源代码网推荐 End Sub
源代码网推荐 </s cript>
源代码网推荐 <form runat=“server”>
源代码网推荐 <asp:Button text=“Enter” OnClick=“SubmitButton_Click” runat=“server” />
源代码网推荐 <asp:label id=“YouEntered”/>
源代码网推荐 </form>
源代码网推荐 </html>
源代码网推荐 在这里你看到了以前在Visual Basic中经常见到的同样的 Load/Unload (装载/卸载)过程。 当页面被装载时,Load事件被激活,这时所有基于服务器的控件都可用。在与用户的交互作用过程中会生成其它事件。最后,当页面被卸载时激活 Unload事件。
源代码网推荐
源代码网推荐        
源代码网推荐        

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华