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)

(Limited to 3 for example)

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(" <div Class=""bar-row"">"))  Dim btnButton As New Button() With {.Text = button, .ID = id, .CssClass = vRiskActive}          If id = "btnElec" Then             AddHandler btnButton.Click, AddressOf btnRiskItem_1 ' here Buttons is your Handler           End If         If id = "btnFire" Then             AddHandler btnButton.Click, AddressOf btnRiskItem_2 ' here Buttons is your Handler           End If         If id = "btnGas" Then             AddHandler btnButton.Click, AddressOf btnRiskItem_3 ' here Buttons is your Handler           End If          If (oGetPercentages.SumTotal) <> "0" Then             ChartArea.Controls.Add(btnButton)             ChartArea.Controls.Add(New LiteralControl("  <div Class=""bar-data"">" & "      <div Class=""bar-inner"">" & " <div Class=""bar bar-high"" style=""width:  " & (oGetPercentages.HighPer) & "%"">" & high & "</div>" & "          <div class=""bar bar-med"" style=""width: " & (oGetPercentages.MedPer) & "%"">" & medium & "</div>" & "  <div class=""bar bar-low"" style=""width: " & (oGetPercentages.LowPer) & "%"">" & low & "</div>" & "          <div class=""bar bar-na"" style=""width: " & (oGetPercentages.NAPer) & "%"">" & na & "</div>" & "      </div>" & "  </div>" & "</div>"))         Else             ChartAreaGrey.Controls.Add(btnButton)             ChartAreaGrey.Controls.Add(New LiteralControl("  <div class=""bar-data"">" & "      <div class=""bar-inner bar-inactive"">" & "  </div>" & "  </div>" & "</div>"))         End If      End Sub 

Now clunky.... (I've limited to 3 for example)

Public Sub btnRiskItem_1()         Call PrcDash2("1")     End Sub      Public Sub btnRiskItem_2()         Call PrcDash2("2")     End Sub      Public Sub btnRiskItem_3()         Call PrcDash2("3")     End Sub 

Replay

Category: beginner Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.114 (s). 12 q(s)