Ignora collegamentiHome / Blog

Blog


A simple example showing how to run the Page_Load event in an ASP.NET page

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    /// <summary>
    /// This method is executed every time the page is loaded by the browser
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        string message = "Hello World!" +
                            "<br />" +
                            "Today is:" + DateTime.Now.Date.ToShortDateString() + 
                            "<br />" +
                            "Now is:" + DateTime.Now.ToLongTimeString();
        LabelMessage.Text = message;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Test: Page_Load Event in ASP.NET</title>
</head>
<body>
    <form id="formMain" runat="server">
    <asp:Label ID="LabelMessage" runat="server"></asp:Label>
    </form>
</body>
</html>


Category: ASP.NET