Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem attaching multiple buttons to a 1 event handler.
Message
De
06/08/2002 07:12:03
Fausto Garcia
Independent Developer
Lima, Pérou
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00685751
Message ID:
00686507
Vues:
35
This message has been marked as the solution to the initial question of the thread.
Hi Mario,

I took your code and made several changes, finally got it working with the help of some folks from the Peruvian Microsoft User Group. The main ideas are:

1. To explicitly declare an HTML form object.
2. As you did on the code you originally posted, create each and every button control programatically and add them to the form object.
3. To bind a page's public subroutine to the handler of the Click event of each button and place the code needed to handle your query right there.
4. Do all the work on the page's Init event handler.

Here is the full vb code with some additions to test it, as it finally gets (I used VS.NET Beta 2):
Public Class unHandlerComun
    Inherits System.Web.UI.Page
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    ' Agregarlo manualmente para acceder al formulario
    Protected Form1 As System.Web.UI.HtmlControls.HtmlForm
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        Dim oBoton As System.Web.UI.WebControls.Button
        For N = 0 To 25
            oBoton = New System.Web.UI.WebControls.Button()
            oBoton.ID = N.ToString
            oBoton.Text = ChrW(Asc("A") + N)
            AddHandler oBoton.Click, AddressOf MuestraLabel
            Form1.Controls.AddAt(N, oBoton)
        Next
        AddHandler oBoton.Click, AddressOf MuestraLabel
        InitializeComponent()
    End Sub

#End Region

    Public N As Integer = 0

    Public Sub MuestraLabel(ByVal sender As Object, ByVal e As System.EventArgs)
        Label1.Text = "CLICK!" & CType(sender, Button).Text
        'Put the code to handle your specific query here!
    End Sub

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler Button1.Click, AddressOf MuestraLabel
    End Sub

    'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    '    MuestraLabel(sender, e)
    'End Sub
End Class
You might be interested on following the discussion I posted there on MUG Peru's site, if so click here and look for it, it's named "Varios botones y un solo handler". Credits go for the folks in there! ;)

Greetings, really hope this helps!
Solo se que nada se

Fausto J. Garcia Pino - MCSD.NET
.NET, Oracle, Tronador & Fondismo!
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform