?
Solved

I think I need to override a user control's host page event? How ?

Posted on 2011-03-22
3
Medium Priority
?
748 Views
Last Modified: 2012-05-11
Hi,

I have a Page_loadComplete event in the Host page of a User Control. However for 3 out of 10 User controls I need to ignore the host page's implementation of this event and use a specific version for the 3 user controls in question.

My first thought was to code an "Overrides" event in the User Control CBH? But not sure if this is the way to do this and how?

Thoughts and code greatly appreciated?

Thanks,

Sam
'Host Page code
Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete

'Standard code here

End Sub

'User control code idea, possibly... Does not work.
Protected Overrides Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete

'Custom User Control Code here, ignoring/Overriding Standard Host Page code.

End Sub

Open in new window

0
Comment
Question by:SamJolly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 35188703
You won't be able to "ignore" the host page's Page_LoadComplete using any mechanism from within the UserControl--they are two different classes. What you can do is go to your hosting page and create the Overrides OnLoadComplete() method. Inside of this sub, be sure not to call MyBase.OnLoadComplete.

Protected Overrides Sub OnLoadComplete(ByVal e As System.EventArgs)
End Sub

Open in new window


Now if you are sharing the host page between several of these user controls (using LoadControl() to include the user control into your page), then you'll need to a little bit of work. You *could* create a Shared boolean member in your hosting page that serves as a flag to indicate whether or not to ignore calling the hosting page's OnLoadComplete() method:

Partial Public Class _Default
    Inherits System.Web.UI.Page

    Private Shared _ignoreLoadComplete As Boolean

    Protected Overrides Sub OnLoadComplete(ByVal e As System.EventArgs)
        If Not _ignoreLoadComplete Then
            MyBase.OnLoadComplete(e)
        End If
    End Sub

    Public Shared Property IgnoreLoadComplete() As Boolean
        Get
            Return _ignoreLoadComplete
        End Get
        Set(ByVal value As Boolean)
            _ignoreLoadComplete = value
        End Set
    End Property

End Class

Open in new window


Then, in the user control's you want to ignore, you can set this value inside of any of the events that occur prior to LoadComplete. OnLoad() would be one example:

Public Partial Class WebUserControl1
    Inherits System.Web.UI.UserControl

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        _Default.IgnoreLoadComplete = True

        MyBase.OnLoad(e)
    End Sub
End Class

Open in new window


Just be sure to reset the value for any pages that you don't want to ignore LoadComplete!
0
 

Author Closing Comment

by:SamJolly
ID: 35189783
thks. Great help although I ended up doing a variation on the theme!!! However you got me going in the right direction. I ended up using a flag "Property" from a business class which defaulted to false and the PageLoaded code always checked this flag before deciding what to do. THe flag was then always set back to false thus ensuring only the exception produced the different processing. Thanks again for your prompt and grt help.
Sam
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35189847
NP. Glad to help  = )
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question