Event Not Firing?

Discussion in 'ASP .Net' started by Don Q., Oct 17, 2007.

  1. Don Q.

    Don Q. Guest

    Hi,

    I'm writing a class in VB that will (once I get it working) be rolled
    up into a DLL for use in all our web applications. However I'm
    running into problems with button events not firing.

    Essentially, my (trimmed-down) code contains this:

    Public Class ModalDialog
    Protected WithEvents btnYes As New Button

    Public Event ButtonClick(ByVal sender As Object, ByVal e As
    System.EventArgs)

    Private Sub btnClick(ByVal sender As Object, ByVal e As
    System.EventArgs)
    RaiseEvent ButtonClick(sender, e)
    End Sub

    Public Sub SomeSubThatIKnowIsFiring()
    AddHandler btnYes.Click, AddressOf btnClick
    End Sub
    End Class

    Then, within the actual page code-behind, I have the following:

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

    Dim MD As New ModalDialog

    Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
    AddHandler MD.ButtonClick, AddressOf GetButtonClick
    MyBase.OnInit(e)
    End Sub

    Protected Sub GetButtonClick(ByVal sender As Object, ByVal e As
    System.EventArgs)
    Dim btn As Button = DirectCast(sender, Button)
    Msg.InnerHtml = btn.CommandName
    End Sub
    End Class

    In the course of my playing around, I've found that although
    ModalDialog.SomeSubThatIKnowIsFiring does indeed fire (as the name
    implies), the btnClick sub (which should be raising the event) never
    actually executes when I click the button.

    I know this code (or its equivalent) should work in Windows
    development, but this is my first foray into trying to handle custom
    events within a web application. Could somebody point out what I'm
    doing wrong, or provide a link to a good guide to handling custom
    events, and persisting them upward from within a class up to the page
    level?

    Regards,
    Don Q.
     
    Don Q., Oct 17, 2007
    #1
    1. Advertisements

  2. Don Q.

    bruce barker Guest

    is the button added to the page? do you see it render? in asp.net
    controls use a round about method to raise events.

    the user clicks the button, the browser posts the from to the server,
    the server creates a new page instance, and fire the page cycle events,
    if the control that performed the postback get notified it caused the
    postback. it then raises the correct postback event (say onclick).

    -- bruce (sqlwork.com)
     
    bruce barker, Oct 18, 2007
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.