SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:


    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Arrays.aspx.vb" Inherits="Arrays" %>
    and nothing displays, when I change it to
    Code:
    <%@ 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:


    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>

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,157
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    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
    Code:
    <%@ 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
    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Arrays.aspx.vb" Inherits="Arrays" %>
    Code:
        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

  3. #3
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •