Streamlining button creation and Handlers The code below works but I can not help thinking it's to 'clunky' and could be so much tidier! It's the first time I've really used AddHandler so go gentle...

Create button(s) and handler(s)

The code below works but I can not help thinking it's to 'clunky' and could be so much tidier! It's the first time I've really used AddHandler so go gentle...


Create button(s) and handler(s)

 Public Sub AddChartRow(ByVal button As String, ByVal id As String, ByVal high As Integer, ByVal medium As Integer, ByVal low As Integer, ByVal na As Integer)

    ChartArea.Controls.Add(New LiteralControl(" &lt;div Class=""bar-row""&gt;"))

    Dim btnButton As New Button() With {.Text = button, .ID = id, .CssClass = vRiskActive}

            If id = "btn1" Then
                AddHandler btnButton.Click, AddressOf btnItem_1 ' here Buttons is your Handler  
            End If
            If id = "btn2" Then
                AddHandler btnButton.Click, AddressOf btnItem_2 ' here Buttons is your Handler  
            End If
            If id = "btn3" Then
                AddHandler btnButton.Click, AddressOf btnItem_3 ' here Buttons is your Handler  
            End If
If id = "btn4" Then
                AddHandler btnButton.Click, AddressOf btnItem_4 ' here Buttons is your Handler  
            End If
If id = "btn5" Then
                AddHandler btnButton.Click, AddressOf btnItem_5 ' here Buttons is your Handler  
            End If
If id = "btn6" Then
                AddHandler btnButton.Click, AddressOf btnItem_6 ' here Buttons is your Handler  
            End If
If id = "btn7" Then
                AddHandler btnButton.Click, AddressOf btnItem_7 ' here Buttons is your Handler  
            End If
If id = "btn8" Then
                AddHandler btnButton.Click, AddressOf btnItem_8 ' here Buttons is your Handler  
            End If

If id = "btn9" Then
                AddHandler btnButton.Click, AddressOf btnItem_9 ' here Buttons is your Handler  
            End If
If id = "btn10" Then
                AddHandler btnButton.Click, AddressOf btnItem_10 ' here Buttons is your Handler  
            End If

            If (oGetPercentages.SumTotal) &lt;&gt; "0" Then
                ChartArea.Controls.Add(btnButton)
                ChartArea.Controls.Add(New LiteralControl("  &lt;div Class=""bar-data""&gt;" &amp; "      &lt;div Class=""bar-inner""&gt;" &amp; " &lt;div Class=""bar bar-high"" style=""width:  " &amp; (oGetPercentages.HighPer) &amp; "%""&gt;" &amp; high &amp; "&lt;/div&gt;" &amp; "          &lt;div class=""bar bar-med"" style=""width: " &amp; (oGetPercentages.MedPer) &amp; "%""&gt;" &amp; medium &amp; "&lt;/div&gt;" &amp; "  &lt;div class=""bar bar-low"" style=""width: " &amp; (oGetPercentages.LowPer) &amp; "%""&gt;" &amp; low &amp; "&lt;/div&gt;" &amp; "          &lt;div class=""bar bar-na"" style=""width: " &amp; (oGetPercentages.NAPer) &amp; "%""&gt;" &amp; na &amp; "&lt;/div&gt;" &amp; "      &lt;/div&gt;" &amp; "  &lt;/div&gt;" &amp; "&lt;/div&gt;"))
            Else
                ChartAreaGrey.Controls.Add(btnButton)
                ChartAreaGrey.Controls.Add(New LiteralControl("  &lt;div class=""bar-data""&gt;" &amp; "      &lt;div class=""bar-inner bar-inactive""&gt;" &amp; "  &lt;/div&gt;" &amp; "  &lt;/div&gt;" &amp; "&lt;/div&gt;"))
            End If

        End Sub



 Public Sub btnItem_1()
            Call PrcDash2("1")
        End Sub

        Public Sub btnItem_2()
            Call PrcDash2("2")
        End Sub

        Public Sub btnItem_3()
            Call PrcDash2("3")
        End Sub 

 Public Sub btnItem_4()
            Call PrcDash2("4")
        End Sub

 Public Sub btnItem_5()
            Call PrcDash2("5")
        End Sub

 Public Sub btnItem_6()
            Call PrcDash2("6")
        End Sub

 Public Sub btnItem_7()
            Call PrcDash2("7")
        End Sub

 Public Sub btnItem_8()
            Call PrcDash2("8")
        End Sub

 Public Sub btnItem_9()
            Call PrcDash2("9")
        End Sub

 Public Sub btnItem_10()
            Call PrcDash2("10")
        End Sub
The Button control/class has a Tag property of type Object. You could simply pass to that property your strings "1", "2" etc. In this way you would only need one eventhandler where you the read the value of the Tag property back, call the ToString() method and then pass this string as argument to the PrcDash2() method.