Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Problem with adding button to form at runtime


Message #1 by "Matthew Killick" <mkill22@t...> on Fri, 19 Apr 2002 14:03:16 +0100
Try this instead:

AddHandler boxb.Click, New System.EventHandler(AddressOf boxb_Click)

Sub btnBoxSearch_Click(ByVal sender As Object, ByVal e As EventArgs)
        lblOutMessage.Text = "Box Search"
End Sub

----Original Message Follows----
From: "Matthew Killick" <mkill22@t...>
Reply-To: "ASPX_Professional" <aspx_professional@p...>
To: "ASPX_Professional" <aspx_professional@p...>
Subject: [aspx_professional] Problem with adding button to form at runtime
Date: Fri, 19 Apr 2002 14:03:16 +0100

Hi,

I'm using VB.NET to create an ASP.NET web form and have the following
problem.

I need to add a button to a table within a form at runtime which I can
do ok using this code (I'm using code behind):

                    Dim boxb As New Button()
                    boxb.ID = "btnBoxSearch"
                    boxb.Text = "Find Box Offices"
                    boxb.Visible = True
                    cell1.Controls.Add(boxb)
                    AddHandler boxb.Click, AddressOf
Me.btnBoxSearch_click

The button appears on the form ok.

The problem is that I can't get the event handler to work when the
button is clicked.

The code for the event handler is:

Sub btnBoxSearch_click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnBoxSearch.Click
        lblOutMessage.Text = "Box Search"
End Sub

I've added this to the top of the code:

             Protected WithEvents btnBoxSearch As
System.Web.UI.WebControls.Button

But at runtime clicking the button just reloads the page! Nothing is
written to the label at all.

Can anyone help, this is driving me nuts.

Cheers,
Matt






_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


  Return to Index