personalityDropDownList.Items.Add(new ListItem("extraverted")); 页面事件: public partial class EventPage : System.Web.UI.Page { public EventPage() { this.Load += new EventHandler(EventPage_Load); } void EventPage_Load(object sender, EventArgs e) { Trace.Write("Load event fired (manual delegate wireup)"); } void _clickMeButton_Click2(object sender, EventArgs e) { Trace.Write("Click event handler for Button fired (manual delegate wireup)"); } protected override void OnLoad(EventArgs e) { Trace.Write("Virtual OnLoad method called"); base.OnLoad(e); } protected void Page_Init(object sender, EventArgs e) { Trace.Write("Page_Init handler called (implicit wire-up)"); _clickMeButton.Click += new EventHandler(_clickMeButton_Click2); } protected void Page_Load(object sender, EventArgs e) { Trace.Write("Page_Load handler called (implicit wire-up)"); } protected void _clickMeButton_Click(object sender, EventArgs e) { Trace.Write("Click event handler for Button fired (declarative delegate wireup)"); _messageLabel.Text = "You last clicked the button at " + DateTime.Now.ToLongTimeString(); } } 两种非后置的代码布置: <%@ Page Language="C#" Debug="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <mce:script runat="server"><!-- const int _itemCount = 10; string GetDisplayItem(int n) { return "Item #" + n.ToString(); } // --></mce:script> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Simple page</title> </head> <body> <h1>Test ASP.NET 2.0 Page</h1> <ul> <% for (int i=0; i<_itemCount; i++) { %> <li><%=GetDisplayItem(i)%></li> <% } %> </ul> <% Response.Write("<h2>Total number of items = " + _itemCount.ToString() + "</h2>"); %> <%= GetType().Assembly.Location %> </body> </html> <%@ Page Language="C#" %> <mce:script runat="server"><!-- const int _itemCount = 10; string GetDisplayItem(int n) { return "Item #" + n.ToString(); } protected override void Render(HtmlTextWriter writer) { writer.Write("<!DOCTYPE html PUBLIC /"-//W3C//DTD " + "XHTML 1.0 Transitional//EN/" /"http://www.w3" + ".org/TR/xhtml1/DTD/xhtml1-transitional.dtd/">"); writer.Write("/r/n/r/n<html xmlns=/"http://www.w3.org/" + "1999/xhtml/" >/r/n<head>/r/n<title>Simple page<" + "/title>/r/n</head>/r/n<body>/r/n" + "<h1>Test ASP.NET 2.0 Page</h1>/r/n " + "<ul>/r/n "); for (int i = 0; i < _itemCount; i++) { writer.Write("/r/n<li> "); writer.Write(GetDisplayItem(i)); writer.Write("</li>/r/n "); } Response.Write("<h2>Total number of items = " + _itemCount.ToString() + "</h2>"); writer.Write("/r/n</body>/r/n</html>/r/n"); base.Render(writer); } // --></mce:script>