1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents phl As System.Web.UI.WebControls.PlaceHolder
Protected WithEvents BT_ADD_CONTROL As System.Web.UI.WebControls.Button
<Serializable()> Private Structure bt
Dim id As String
Dim valeur As String
End Structure
Dim al As New ArrayList()
#Region " Code généré par le Concepteur Web Form "
'Cet appel est requis par le Concepteur Web Form.
<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*: cet appel de méthode est requis par le Concepteur Web Form
'Ne le modifiez pas en utilisant l'éditeur de code.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Placez ici le code utilisateur pour initialiser la page
If IsPostBack Then
Try
Dim item As Object
al = CType(viewstate("al"), ArrayList)
For Each item In al
Dim NewBtn As New Button()
NewBtn.ID = item.id
NewBtn.Text = item.valeur
AddHandler NewBtn.Click, AddressOf BT_ADD_CONTROL_Click
phl.Controls.Add(NewBtn)
Next
Catch
End Try
End If
End Sub
Private Sub BT_ADD_CONTROL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT_ADD_CONTROL.Click
Dim NewBtn As New Button()
Dim myvalue As Integer
Randomize()
myvalue = CInt(Int((100 * Rnd()) + 1))
NewBtn.ID = "bt_" & myvalue
NewBtn.Text = "bouton" & myvalue
AddHandler NewBtn.Click, AddressOf BT_ADD_CONTROL_Click
phl.Controls.Add(NewBtn)
Try
Dim bt_save As New bt()
bt_save.id = NewBtn.ID
bt_save.valeur = NewBtn.Text
If IsNothing(al) Then
al = New ArrayList()
End If
al.Add(bt_save)
Catch err As SystemException
err.ToString()
End Try
viewstate("al") = al
End Sub
End Class |
Partager