locked
webFormView event question, why? RRS feed

  • Question

  • User1755877086 posted
    Hi, I have been looking at the code, and I am really curious as to why the constructor raises an event: Public Sub New() AddHandler Me.Load, AddressOf WebFormView_Load End Sub ..as opposed to simply calling the method, eg Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load WebFormView_Load() End Sub Maybe it is just a different programming style, or is it somehow "better" programming practice to do it in this way? Can anyone confirm? Cheers, yogi
    Wednesday, June 2, 2004 10:34 AM

All replies

  • User541108374 posted
    Hi, actually the constructor doesn't raise an event. It adds an eventhandler to the page. A little example in vb.net: Normally you would have an instance member like this Protected WithEvents testButton As Button and somewhere in code private sub testButton_Click(sender as object, e as eventargs) handles testButton.Click well, instead of this mechanism you could rewrite that as: Protected testButton as Button 'The withevents keyword is gone and in your page_load or Page_init: AddHandler testButton.Click, AddressOf testButton_Click and your method: private sub testButton_Click(sender as object, e as eventargs) 'Handles is gone here It's just another way of writing. I've read somewhere that one argued that the latter way is faster but didn't check it out yet. Grz, Kris.
    Wednesday, June 2, 2004 1:16 PM
  • User1755877086 posted
    Kris<<actually the constructor doesn't raise an event. It adds an eventhandler to the page. >> ..sorry, that's what i meant to say:-). Ah well, thanks for satisfying my curiosity. ta, yogi
    Wednesday, June 2, 2004 5:35 PM