From code analysis (Visual studio), I got this warning:
Warning 2 CA2000 : Microsoft.Reliability : ... Call System.IDisposable.Dispose on object 'l' before all references to it are out of scope...
So, I changed the code :
Dim l As LiteralControl = New LiteralControl
AddHandler l.DataBinding, AddressOf OnDataBinding
container.Controls.Add(l)
to
Dim l As LiteralControl = Nothing
Try
l = New LiteralControl
AddHandler l.DataBinding, AddressOf OnDataBinding
container.Controls.Add(l)
Finally
If Not l Is Nothing Then
l.Dispose()
End If
End Try
The warning disappear but then the literal control isn't anymore being displayed on the page...
EDIT
Note that the code come from a Microsoft web page : http://msdn.microsoft.com/en-us/library/system.web.ui.itemplate.instantiatein.aspx