Page_Load not firing in web user control ascx.vb

  • Thread starter Thread starter C K
  • Start date Start date
C

C K

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
 
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.
 
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
 
Back
Top