Understanding Page Language and AutoEventWireUp

When I am using the Sitepoint "Build your own ASP.NET 3.5 Website book (in VB.Net) I am creating new pages and typing out the examples. When I do this the first line looks like:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Arrays.aspx.vb" Inherits="Arrays" %>

and nothing displays, when I change it to

<%@ Page Language="VB" %>

it works. What is the reason or shall I keep changing the code and come back to it at the end of the book>

Full code:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Arrays.aspx.vb" Inherits="Arrays" %>

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

<!-- Array data -->
<script runat="server">

    Sub Page_load()
        Dim drinkList(4) As String
        drinkList(0) = "Water"
        drinkList(1) = "Juice"
        drinkList(2) = "Soda"
        drinkList(3) = "Milk"
        drinkLabel.Text = drinkList(1)
    End Sub
</script>
<!-- End of Array Data -->

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <!--Create label for data to show in -->
        <asp:Label ID="drinkLabel" runat="server" />
    </div>
    </form>
</body>
</html>

In this particular situation it is the AutoEventWireup that is stopping you from having the page working.

AutoEventWireup (defaults to True), when not provided (not sure why the default template is False for it), but that tells ASP.NET to automatically apply events for methods Page_Load(), Page_PreRender, Page_Render, etc (see asp.net page life cycle).

Another approach, if you leave the initial line the way it was

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Arrays.aspx.vb" Inherits="Arrays" %>

You can change “false” to “true”, that will make it work.

Or when leaving it false, change your Page_Load method

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Arrays.aspx.vb" Inherits="Arrays" %>
    Sub Page_load() Handes NameOfPage.Load
        Dim drinkList(4) As String
        drinkList(0) = "Water"
        drinkList(1) = "Juice"
        drinkList(2) = "Soda"
        drinkList(3) = "Milk"
        drinkLabel.Text = drinkList(1)
    End Sub

Thank you, sounds like it’s one to chalk up to a Microsoft “quirk” then. I just wanted to make sure it was VB not me in this case and what the reason was.