Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Protected Sub btnView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnView.Click
      con = New SqlConnection(constr)
Dim btnDynamic As New Button

VB
btnDynamic.ID = "btnDynamic"
       btnDynamic.Text = "Dynamic Button"

VB
AddHandler btnDynamic.Click, AddressOf OnClick
     form1.Controls.Add(btnDynamic)
Private Sub OnClick(ByVal sender As Object, ByVal e As System.EventArgs)
       
            Dim buttonId As String
            buttonId = DirectCast(sender, Button).ID
            Response.Write("Button clicked: " + buttonId)
 
    End Sub
Posted
Updated 30-Oct-12 4:35am
v2
Comments
OriginalGriff 30-Oct-12 4:07am    
And your question is?
Akinmade Bond 30-Oct-12 9:34am    
I can't see your question

Why?? Just move the code that you've put in the click event handler to it's own method and call it from the button click handler or from anywhere else you need to.

There's very little reason to "Click" a button to execute a piece of code.
 
Share this answer
 
rise the click event wherever you want like this........
VB
btn.Click += new EventHandler(btn_Click);

then you manually write the below method...........
VB
protected void btn_Click(objectsender e,Eventargs args)
{
}

simple...........
 
Share this answer
 
v2
Comments
Simon_Whale 30-Oct-12 13:17pm    
the OP has already written the event handler for his application, but it lacks a question. Also your answer was in C# when the OP is working with VB.NET

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900