::细细品味ASP.NET (三)::

    技术2022-05-11  109

    细细品味ASP.NET (三)

    青苹果工作室(编译)
    01-5-18 上午 09:41:52
    页面事件
    在此前我提到 ASP.NET已经被从头到脚地重写了,但是我并没有指出它是按照面向对象的思路重建的。在对象树的顶部是Page对象,即页面对象,ASP.NET的每个控件、应用程序和页面都是从这个对象中继承来的,也就是说每个页面都是页面对象的一个例示。页面的Load (装载)事件是一个非常重要的事件,如下面的表3代码所示:
    表3 使用页面事件
    <html>
    <script 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
    </script>
    <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)