sto imparando e forse non è quello che cerchi. Comunque:
Ho un form vuoto e lo riempio dinamicamente con un textbox, un pulsante ed una label. Costruisco pure l'evento click del pulsante
Pagina.asx
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="a.aspx.vb" Inherits="corso_apogeo.a7"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>a</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<LINK href="../Stile.css" type="text/css" rel="stylesheet">
</HEAD>
<body style="BACKGROUND-COLOR: #ffffcc">
<form id="Form1" method="post" runat="server">
</form>
</body>
</HTML>
Codice:
Public Class a7
Inherits System.Web.UI.Page
Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
#Region " Codice generato da Progettazione Web Form "
'Chiamata richiesta da Progettazione 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: questa chiamata al metodo è richiesta da Progettazione Web Form.
'Non modificarla nell'editor del codice.
InitializeComponent()
End Sub
#End Region
Private Function GetForm() As HtmlForm
Return CType(Me.FindControl("Form1"), HtmlForm)
End Function
Private Function GetLabel() As Label
Return CType(Me.FindControl("lbl1"), Label)
End Function
Private Function GetTextBox() As TextBox
Return CType(Me.FindControl("tb1"), TextBox)
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
This = Me
Dim tb As New TextBox()
tb.ID = "tb1"
tb.Text = "Scrivi qualcosa"
Me.GetForm().Controls.Add(tb)
Me.GetForm().Controls.Add(New LiteralControl("<br>"))
Dim btn As New Button()
btn.Text = "Spedisci"
Me.GetForm().Controls.Add(btn)
AddHandler btn.Click, AddressOf btn1_click
Me.GetForm().Controls.Add(New LiteralControl("<br>"))
Dim lbl As New Label()
lbl.ID = "lbl1"
Me.GetForm().Controls.Add(lbl)
End Sub
Private Sub btn1_click(ByVal Sender As Object, ByVal e As System.EventArgs)
GetLabel().Text = "Mi hai chimato, finalmente!<br>Mi hai spedito: " & Me.GetTextBox().Text
End Sub
End Class