Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-27-2012, 10:40 AM   PM User | #1
code-in-time
New Coder

 
Join Date: Mar 2012
Posts: 59
Thanks: 65
Thanked 0 Times in 0 Posts
code-in-time is an unknown quantity at this point
Add dynamic Control from a class only

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.



Code:
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
Attached Files
File Type: zip WebSite2 -dynamic control.zip (3.8 KB, 33 views)
code-in-time is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:52 AM.


Advertisement
Log in to turn off these ads.