[ASP.NET 2] ContentPlaceHolderID

S

SBerry

hello,
I would like to create some Content server controls at runtime within
Page_InitComplete code
unfortunately I got exception :(

"Setting the ContentPlaceHolderID property of
System.Web.UI.WebControls.Content is not supported"

what can I do?
 
C

Casper Stendal

Hi

I'm having exactely the same problem - but still no solution... Too me it
looks like a bug, but I don't hope so...

My old "unanswered question":
-------
Everything about the MasterPages loaded dynamicly, just works fine... BUT
when i try to add the Content "boxes" dynamicly to the .aspx page, I get
problems...

My code:
Dim myContent As Content = New Content()
Page.Page.Controls.Add(myContent)
myContent.ContentPlaceHolderID = "ContentPlaceHolder1"

The error:
Setting the ContentPlaceHolderID property of
System.Web.UI.WebControls.Content is not supported.

Shouldn't this work...? For me it look likes an error in the ASP.NET 2.0..?
 
C

Casper Stendal

Hi again,

This time I come with GOOD news - I found a solution!

Instead of making the Content control, you can just access the
ContentPlaceHolder's from the MasterPage and add your content this way -
still at runtime...

Like this:
---
Dim PlaceHolder1 As ContentPlaceHolder =
Master.FindControl("ContentPlaceHolder1")
Dim lblTxt As Label = New Label()
lblTxt.Text = "Text for ContentPlaceHolder1"
PlaceHolder1.Controls.Add(myTextHolder)
 
C

Casper Stendal

There was a little bug in the code, so here comes a functional version:
---
Dim PlaceHolder1 As ContentPlaceHolder =
Master.FindControl("ContentPlaceHolder1")
Dim lblTxt As Label = New Label()
lblTxt.Text = "Text for ContentPlaceHolder1"
PlaceHolder1.Controls.Add(lblTxt)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top