简体   繁体   中英

asp.net event handler not firing

I've been looking for a solution to this for several hours now and cannot find a solution.

The Scenario:

  • I have a masterpage baseclass (called basemaster)
  • All of my master pages inherit from basemaster
  • basemaster defines an event 'Public Event HandleClickEvent As EventHandler'
  • I have a masterpage named master1
  • master1 defines an event handler 'Public Shadows Event HandleClickEvent As EventHandler'
  • master1 has a user control named usr1
  • usr1 has a button that raises event ButtonClicked when clicked
  • I have a page (thePage) that uses master1
  • thePage has a button click event handler that it registers like so: 'AddHandler Master.HandleClickEvent, AddressOf HandleTheClick'
  • master1 has code something like:

    Protected Sub Usr1_ButtonClicked(ByVal sender As Object, ByVal e As System.EventArgs) Handles Usr1.ButtonClicked RaiseEvent HandleClickEvent(sender, e) End Sub

  • when thePage loads I see it register the handler on master1

  • when the button is clicked, Usr1_ButtonClicked is fired and I step through the RaiseEvent but HandleClickEvent on thePage is never reached.

I think I'm doing something stupid. I would appreciate some help.

Thanks!

Does the event on your master page class need to be an actual event handler? You should be able to just make it a public method and access it from your page (or user control) event handler like this:

Page.Master.MyPublicMasterPageMethod()

To call a method on your content page from your master page you could use VB's CallByName method: http://msdn.microsoft.com/en-us/library/22x2chfx.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM