...

View Full Version : Add dynamic Control from a class only



code-in-time
05-27-2012, 10:40 AM
Hi,Please can you help

I'm trying to add a control to alot of pages dynamically from an object.


error :The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).


I cant remove the code blocks <% = %> - because there are to many pages to edit
I cant add a place holder - because there are to many pages to edit
Everything must be added from my class



I have attached a simple example project.




Public Class MyObject

Public Sub AddControl()

Dim p As Page = HttpContext.Current.CurrentHandler

Dim myLabel As New Label()

myLabel.Text = "Sample Label"
myLabel.ID = "test"


p.Form.Controls.Add(myLabel)

End Sub

End Class




Please can you help? Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum