in effetti il framework 2 è MOLTO diverso dal precedente:
questa è solo una prova
MioUserControl.ascx (ha un semplice label)
codice:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="MioUserControl.ascx.vb" Inherits="MioUserControl" %>
<asp:Label ID="Label1" runat="server"></asp:Label>
MioUserControl.ascx.vb (ha una proprietà pubblica aLABEL)
codice:
Partial Class MioUserControl
Inherits System.Web.UI.UserControl
Public Property aLABEL() As Label
Get
Return Me.Label1
End Get
Set(ByVal value As Label)
Me.Label1 = value
End Set
End Property
End Class
pagina che contiene il controllo loadMioUserControl.aspx
codice:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="loadMioUserControl.aspx.vb" Inherits="Prove_loadMioUserControl" %>
<%@ Reference Control="~/Prove/MioUserControl.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder runat="server" ID="ph1"/>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
loadMioUserControl.aspx.vb
codice:
Partial Class Prove_loadMioUserControl
Inherits System.Web.UI.Page
Protected WithEvents uc As MioUserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
uc = DirectCast(Me.LoadControl("~/Prove/MioUserControl.ascx"), MioUserControl)
uc.aLABEL.Text = "Ciao, Mondo"
Me.ph1.Controls.Add(uc)
End Sub
End Class