Professional Web Applications Themes

Page_Load not firing in web user control ascx.vb - ASP.NET General

I am having trouble getting the page_load event to fire from within my usercontrol - my code is below, I'm sure I'm missing something simple. Just your basic web user control - I've just began using them. My aspx page is simple: <% Register TagPrefix="TestPoll" TagName="Message" Src="poll.ascx" %> .... <form id="Form1" method="post" runat="server"> <TestPoll:Message runat="server" ID="Message1"/> </form> .... My user control is also plain jane- I have a label on it called label1 - here is my code in the *.ascx.vb file. I can get a button_click event to fire from code contained in the *.ascx.vb Sub Page_Load(ByVal Src As ...

  1. #1

    Default Page_Load not firing in web user control ascx.vb

    I am having trouble getting the page_load event to fire from within my
    usercontrol - my code is below, I'm sure I'm missing something simple.

    Just your basic web user control - I've just began using them.
    My aspx page is simple:

    <% Register TagPrefix="TestPoll" TagName="Message" Src="poll.ascx" %>
    ....
    <form id="Form1" method="post" runat="server">
    <TestPoll:Message runat="server" ID="Message1"/>
    </form>
    ....
    My user control is also plain jane- I have a label on it called label1 -
    here is my code in the *.ascx.vb file. I can get a button_click event to
    fire from code contained in the *.ascx.vb

    Sub Page_Load(ByVal Src As Object, ByVal E As EventArgs)
    Label1.Text = "run" 'c.LastName
    End Sub

    What am I missing?

    Clayton


    C Guest

  2. #2

    Default Re: Page_Load not firing in web user control ascx.vb

    You may want to expand the Web Form Designer generated code region and make
    sure that there is an event handler set up for the page load event. I'm not
    a VB guy, but in C# you need to have:

    this.Load += new System.EventHandler(this.Page_Load);

    You'll want to have something similar.


    --
    Chris Jackson
    Software Engineer
    Microsoft MVP - Windows XP
    Windows XP Associate Expert
    --
    "C K" <com> wrote in message
    news:%23$phx.gbl... 


    Chris Guest

  3. #3

    Default Re: Page_Load not firing in web user control ascx.vb

    Thanks guys.

    I added "Handles MyBase.Load" to the end of the page_load declaration and it
    works.

    New Code:
    Sub Page_Load(ByVal Src As Object, ByVal E As EventArgs) Handles MyBase.Load

    Old Code:

    Sub Page_Load(ByVal Src As Object, ByVal E As EventArgs)

    Also, an alternative would be to change the autoeventwireup = true (VS
    defaults it to false)



    Cheers,

    Clayton



    "Dino Chiesa [MSFT]" <com> wrote in message
    news:%23$phx.gbl... 
    > make 
    > not [/ref][/ref]
    label1 - [/ref]
    > to 
    > >
    > >[/ref]
    >
    >[/ref]


    C Guest

Similar Threads

  1. Page_Load called more than once for user control - newbie question
    By keith in forum ASP.NET Building Controls
    Replies: 0
    Last Post: November 5th, 08:03 PM
  2. Access User Control value during Page_Load
    By Cindy in forum ASP.NET Building Controls
    Replies: 1
    Last Post: June 26th, 12:18 AM
  3. Replies: 0
    Last Post: May 5th, 02:26 PM
  4. Replies: 5
    Last Post: February 24th, 02:07 PM
  5. Access to Page_Load Event from the .ascx control
    By Nikolaus Hruska in forum ASP.NET Building Controls
    Replies: 0
    Last Post: July 2nd, 03:04 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139