Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 135933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:52:07+00:00 2026-05-11T06:52:07+00:00

I would like some code to execute at the preload stage of my usercontrol’s

  • 0

I would like some code to execute at the ‘preload’ stage of my usercontrol’s lifecycle. However the preload event is only available on the Page object. So, I added the following method to my usercontrol:

Private Sub Page_PreLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Page.PreLoad  

However, I know get the compile error: ‘Handles clause requires a WithEvents variable defined in the containing type or one of its base types’

As the Page property is inherited from UserControl I don’t see how this can easily be done.

Any help gratefully received!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:52:08+00:00Added an answer on May 11, 2026 at 6:52 am

    I apologize for giving a C# example but I can’t remember how to do it in VB…

    Anyway, in your UserControl’s Init you could explicitly assign your Page_PreLoad method as the handler for the PreLoad event of the UserControl’s Page property instead of using the ‘Handles’ syntax in the method declaration. What your example is doing is trying to assign an event handler to an event on the UserControl object for an event that the UserControl object doesn’t raise. As you noted, UserControl doesn’t inherit from Page, which is where the PreLoad event lives. UserControl does, however contain a Page object as one of its properties, which in turn exposes PreLoad as an event to which you can assign a handler. Anyway, this compiles and approaches what it sounds like you are looking for (using C-style comments to preserve WMD syntax highlighting).

    Protected Overrides Sub OnInit(ByVal e As System.EventArgs)     // this assigns Page_PreLoad as the event handler      // for the PreLoad event of the Control's Page property     AddHandler Me.Page.PreLoad, AddressOf Page_PreLoad     MyBase.OnInit(e) End Sub  Private Sub Page_PreLoad(ByVal sender As Object, ByVal e As System.EventArgs)     // do something here End Sub 

    I’m not sure if that serves your purpose–as Stephen Wrighton indicated above, there may be a better way with one of the different events in the page lifecycle. However, building on what he said, this should work because the control’s OnInit is called in which the event handler assignment is made, then the Page’s OnLoad event is raised and then the event handler within the control is executed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a quad core machine and would like to write some code to
I would like to enable/disable some code based on a custom solution configuration I
I have some code that raises PropertyChanged events and I would like to be
I'm writing some code that handles logging xml data and I would like to
I would like to do something like the following: def add(a, b): #some code
On a small embedded system project we have some code which we would like
I've written some C code that I would like to port to python, as
I have some old C code that I would like to combine with some
I'm trying to write some LINQ To SQL code that would generate SQL like
Basically I would like to tell MSTest to execute a bit of code before

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.