:master: un esempio
codice:
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
'creo le label: debbono sempre essere ricreate
For i As Integer = 0 To 3
Dim lbl As New Label()
lbl.ID = "lbl_" & i
lbl.Text = lbl.ID
Me.div1.Controls.Add(lbl)
Me.div1.Controls.Add(New LiteralControl("
"))
Next
End Sub
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'recupero le label dal controllo div e modifico il testo
Dim a As String() = {"Stefano", "Carlo", "Nicola", "Pietro"}
For i As Integer = 0 To a.Length - 1
Dim o As Object = Me.div1.FindControl("lbl_" & i)
If o IsNot Nothing AndAlso o.GetType Is GetType(Label) Then
Dim lbl As Label = DirectCast(o, Label)
lbl.Text = a(i)
End If
Next
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Pagina senza titolo</title>
</head>
<body>
<form id="form1" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Riempi le label</asp:LinkButton>
<div id="div1" runat="server">
</div>
</form>
</body>
</html>
ps. forse è meglio sostituire
If o IsNot Nothing AndAlso o.GetType Is GetType(Label)
con
If TypeOf o Is Label