Home All Groups Group Topic Archive Search About

Custom ContentPlaceHolder

Author
20 Jun 2009 10:50 AM
gerry
Visual Studio 2008 SP1
..NET 3.5 SP1

I am attempting to create a custom ContentPlaceHolder.
The few google results I got for "custom ContentPlaceHolder" state that this
should be a simple matter of deriving a class from ContentPlaceHolder.
Either they are all referring to older versions of the framework /
visualstudio where this did work or I am doing something wrong.


When attempting to use a ContentPlaceHolder derived control on a MasterPage,
the designer shows it very different from a standard ContentPlaceHolder.
Any ContentPages based on this MasterPage show the CustomContentPlaceHolder
as a non-editable area in the designer.
Creating a corresponding Content control on the content page generates a
MasterPage design time error stating that there is no ContentPlaceHolder
corresponding to the Content control.

If I ignore these issues and work 100% in html , everything works peachy at
run time - so this is strictly a designer issue.
My guess is that somewhere something is checking specifically for the
ContentPlaceHolder type and not recognizing ContentPlaceHolder derived
controls as being of the proper type.

I looked throught the associated control/designer/builder classes in
relector but didn't see anything that looked like the culprit.
One thing I couldn't find was the MasterPageWebFormDesigner which according
the MasterPage metadata in vs is supposed to be in
Microsoft.VisualStudio.Web.dll.
Either this class does not exist in this dll or reflector doesn't see it for
some reason.

Attached is a complete simple solution that demonstrates this issue.

Gerry

[attached file: CustomContentPlaceHolder.zip]

Author
22 Jun 2009 8:21 AM
Allen Chen [MSFT]
Hi Gerry,

>I looked throught the associated control/designer/builder classes in
>relector but didn't see anything that looked like the culprit.
>One thing I couldn't find was the MasterPageWebFormDesigner which
according
>the MasterPage metadata in vs is supposed to be in
>Microsoft.VisualStudio.Web.dll.
>Either this class does not exist in this dll or reflector doesn't see it
for
>some reason.

This exception is exactly thrown by MasterPageWebFormDesigner. So I think
it's by design and we cannot do anything to eliminate it. You can submit a
feedback on the connect site to inform our develop team. Our dedicated
engineers will evaluate your feedback and decide whether to improve it in
the future.

https://connect.microsoft.com/VisualStudio/feedback/CreateFeedbackForm.aspx?
FeedbackFormConfigurationID=3471&FeedbackType=2

If you want to look into details, please use reflector to view the code in
Microsoft.VisualStudio.Web.dll. You can download the assembly from:

http://cid-2fa13ebc6cc8e80f.skydrive.live.com/self.aspx/Public/Microsoft.Vis
ualStudio.Web.dll


Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd***@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Are all your drivers up to date? click for free checkup

Author
23 Jun 2009 8:51 PM
fruitbatinshades
Has any progress been made on this issue? I am having the same problem and
wondered if it has been addressed or if someone has found a workaround?

Show quoteHide quote
"Allen Chen [MSFT]" wrote:

> Hi Gerry,
>
> >I looked throught the associated control/designer/builder classes in
> >relector but didn't see anything that looked like the culprit.
> >One thing I couldn't find was the MasterPageWebFormDesigner which
> according
> >the MasterPage metadata in vs is supposed to be in
> >Microsoft.VisualStudio.Web.dll.
> >Either this class does not exist in this dll or reflector doesn't see it
> for
> >some reason.
>
> This exception is exactly thrown by MasterPageWebFormDesigner. So I think
> it's by design and we cannot do anything to eliminate it. You can submit a
> feedback on the connect site to inform our develop team. Our dedicated
> engineers will evaluate your feedback and decide whether to improve it in
> the future.
>
> https://connect.microsoft.com/VisualStudio/feedback/CreateFeedbackForm.aspx?
> FeedbackFormConfigurationID=3471&FeedbackType=2
>
> If you want to look into details, please use reflector to view the code in
> Microsoft.VisualStudio.Web.dll. You can download the assembly from:
>
> http://cid-2fa13ebc6cc8e80f.skydrive.live.com/self.aspx/Public/Microsoft.Vis
> ualStudio.Web.dll
>
>
> Regards,
> Allen Chen
> Microsoft Online Support
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> msd***@microsoft.com.
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
>
> Note: MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 2 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions. Issues of this
> nature are best handled working with a dedicated Microsoft Support Engineer
> by contacting Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
>
Author
24 Jun 2009 2:04 AM
Allen Chen [MSFT]
Hi,

I believe there's no way to workaround this issue. It's a pure designer
issue that is caused by MasterPageWebFormDesigner. You can submit your
feedback in the connect site:

https://connect.microsoft.com/VisualStudio/feedback/CreateFeedbackForm.aspx?
FeedbackFormConfigurationID=3471&FeedbackType=2

Our product team engineers will evaluate your feedback to see if we can
improve this in the future edition of Visual Studio.

Regards,
Allen Chen
Microsoft Online Support
Author
24 Jun 2009 4:03 PM
gerry
Sounds like we are SOL on this one due to some 'by design' bug in the
designer.
My guess is that the master page designer was created by an entry level
summer intern who never saw any reason for anyone to ever derive a custom
placeholder and accordingly they made sure that you couldn't.



Show quoteHide quote
"fruitbatinshades" <fruitbatinsha***@discussions.microsoft.com> wrote in
message news:A6744324-3CDC-41A4-A4FD-81ED794E016A@microsoft.com...
> Has any progress been made on this issue? I am having the same problem and
> wondered if it has been addressed or if someone has found a workaround?
>
> "Allen Chen [MSFT]" wrote:
>
>> Hi Gerry,
>>
>> >I looked throught the associated control/designer/builder classes in
>> >relector but didn't see anything that looked like the culprit.
>> >One thing I couldn't find was the MasterPageWebFormDesigner which
>> according
>> >the MasterPage metadata in vs is supposed to be in
>> >Microsoft.VisualStudio.Web.dll.
>> >Either this class does not exist in this dll or reflector doesn't see it
>> for
>> >some reason.
>>
>> This exception is exactly thrown by MasterPageWebFormDesigner. So I think
>> it's by design and we cannot do anything to eliminate it. You can submit
>> a
>> feedback on the connect site to inform our develop team. Our dedicated
>> engineers will evaluate your feedback and decide whether to improve it in
>> the future.
>>
>> https://connect.microsoft.com/VisualStudio/feedback/CreateFeedbackForm.aspx?
>> FeedbackFormConfigurationID=3471&FeedbackType=2
>>
>> If you want to look into details, please use reflector to view the code
>> in
>> Microsoft.VisualStudio.Web.dll. You can download the assembly from:
>>
>> http://cid-2fa13ebc6cc8e80f.skydrive.live.com/self.aspx/Public/Microsoft.Vis
>> ualStudio.Web.dll
>>
>>
>> Regards,
>> Allen Chen
>> Microsoft Online Support
>>
>> Delighting our customers is our #1 priority. We welcome your comments and
>> suggestions about how we can improve the support we provide to you.
>> Please
>> feel free to let my manager know what you think of the level of service
>> provided. You can send feedback directly to my manager at:
>> msd***@microsoft.com.
>>
>> ==================================================
>> Get notification to my posts through email? Please refer to
>> http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
>>
>> Note: MSDN Managed Newsgroup support offering is for non-urgent issues
>> where an initial response from the community or a Microsoft Support
>> Engineer within 2 business day is acceptable. Please note that each
>> follow
>> up response may take approximately 2 business days as the support
>> professional working with you may need further investigation to reach the
>> most efficient resolution. The offering is not appropriate for situations
>> that require urgent, real-time or phone-based interactions. Issues of
>> this
>> nature are best handled working with a dedicated Microsoft Support
>> Engineer
>> by contacting Microsoft Customer Support Services (CSS) at
>> http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
>> ==================================================
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>>
>>
>>
Author
24 Jun 2009 4:14 PM
gerry
for anyone interested :

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=469940


Show quoteHide quote
"gerry" <germ2@newsgroup.nospam> wrote in message
news:%23CObcVO9JHA.1336@TK2MSFTNGP05.phx.gbl...
> Sounds like we are SOL on this one due to some 'by design' bug in the
> designer.
> My guess is that the master page designer was created by an entry level
> summer intern who never saw any reason for anyone to ever derive a custom
> placeholder and accordingly they made sure that you couldn't.
>
>
>
> "fruitbatinshades" <fruitbatinsha***@discussions.microsoft.com> wrote in
> message news:A6744324-3CDC-41A4-A4FD-81ED794E016A@microsoft.com...
>> Has any progress been made on this issue? I am having the same problem
>> and
>> wondered if it has been addressed or if someone has found a workaround?
>>
>> "Allen Chen [MSFT]" wrote:
>>
>>> Hi Gerry,
>>>
>>> >I looked throught the associated control/designer/builder classes in
>>> >relector but didn't see anything that looked like the culprit.
>>> >One thing I couldn't find was the MasterPageWebFormDesigner which
>>> according
>>> >the MasterPage metadata in vs is supposed to be in
>>> >Microsoft.VisualStudio.Web.dll.
>>> >Either this class does not exist in this dll or reflector doesn't see
>>> >it
>>> for
>>> >some reason.
>>>
>>> This exception is exactly thrown by MasterPageWebFormDesigner. So I
>>> think
>>> it's by design and we cannot do anything to eliminate it. You can submit
>>> a
>>> feedback on the connect site to inform our develop team. Our dedicated
>>> engineers will evaluate your feedback and decide whether to improve it
>>> in
>>> the future.
>>>
>>> https://connect.microsoft.com/VisualStudio/feedback/CreateFeedbackForm.aspx?
>>> FeedbackFormConfigurationID=3471&FeedbackType=2
>>>
>>> If you want to look into details, please use reflector to view the code
>>> in
>>> Microsoft.VisualStudio.Web.dll. You can download the assembly from:
>>>
>>> http://cid-2fa13ebc6cc8e80f.skydrive.live.com/self.aspx/Public/Microsoft.Vis
>>> ualStudio.Web.dll
>>>
>>>
>>> Regards,
>>> Allen Chen
>>> Microsoft Online Support
>>>
>>> Delighting our customers is our #1 priority. We welcome your comments
>>> and
>>> suggestions about how we can improve the support we provide to you.
>>> Please
>>> feel free to let my manager know what you think of the level of service
>>> provided. You can send feedback directly to my manager at:
>>> msd***@microsoft.com.
>>>
>>> ==================================================
>>> Get notification to my posts through email? Please refer to
>>> http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
>>>
>>> Note: MSDN Managed Newsgroup support offering is for non-urgent issues
>>> where an initial response from the community or a Microsoft Support
>>> Engineer within 2 business day is acceptable. Please note that each
>>> follow
>>> up response may take approximately 2 business days as the support
>>> professional working with you may need further investigation to reach
>>> the
>>> most efficient resolution. The offering is not appropriate for
>>> situations
>>> that require urgent, real-time or phone-based interactions. Issues of
>>> this
>>> nature are best handled working with a dedicated Microsoft Support
>>> Engineer
>>> by contacting Microsoft Customer Support Services (CSS) at
>>> http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
>>> ==================================================
>>> This posting is provided "AS IS" with no warranties, and confers no
>>> rights.
>>>
>>>
>>>
>>>
>
>
Author
24 Jun 2009 10:55 PM
Registered User
On Wed, 24 Jun 2009 12:03:47 -0400, "gerry" <germ2@newsgroup.nospam>
wrote:

>Sounds like we are SOL on this one due to some 'by design' bug in the
>designer.
>My guess is that the master page designer was created by an entry level
>summer intern who never saw any reason for anyone to ever derive a custom
>placeholder and accordingly they made sure that you couldn't.
>
Abstractly a nested master page can be considered as a custom
ContentPlaceHolder. Depending upon your needs this might be the way to
go.
http://msdn.microsoft.com/en-us/library/x2b3ktt7.aspx
If so you might want to reconsider the entry level summer intern
comment.

regards
A.G.
Author
25 Jun 2009 4:32 PM
gerry
Sorry, but I am not seeing the relevance.
While that may or may not be true abstractly, concretely it would be design
& maintenance nightmare.

Where one can simply drop multiple CustomContentPlaceHolders on a MasterPage
,
a similar scheme using nested masterpaged would involve basing a MasterPage
on a CustomMasterPage which is based on different CustomMasterPage2 which is
based on another different CustomMasterPage3 etc.
So instead of 1 CustomContentPlaceHolders you are suggesting multiple
CustomMasterPages ?  I don't even want to think about it.

I stick by my intern comment - I see no valid reason to not be able to use a
custom ContentPlaceHolder  the same way we would use any other custom
control.


Show quoteHide quote
"Registered User" <n4***@ix.netcom.com> wrote in message
news:0ra545dn8vfqt7fggm7i9efl7t6ugu2gin@4ax.com...
> On Wed, 24 Jun 2009 12:03:47 -0400, "gerry" <germ2@newsgroup.nospam>
> wrote:
>
>>Sounds like we are SOL on this one due to some 'by design' bug in the
>>designer.
>>My guess is that the master page designer was created by an entry level
>>summer intern who never saw any reason for anyone to ever derive a custom
>>placeholder and accordingly they made sure that you couldn't.
>>
> Abstractly a nested master page can be considered as a custom
> ContentPlaceHolder. Depending upon your needs this might be the way to
> go.
> http://msdn.microsoft.com/en-us/library/x2b3ktt7.aspx
> If so you might want to reconsider the entry level summer intern
> comment.
>
> regards
> A.G.
Author
25 Jun 2009 5:12 PM
gerry
Sorry, but I am not seeing the relevance.
While that may or may not be true abstractly, concretely it would be a
design
& maintenance nightmare.

Where one can simply drop multiple CustomContentPlaceHolders on a MasterPage
,
a similar scheme using nested masterpaged would involve basing a MasterPage
on a CustomMasterPage which is based on different CustomMasterPage2 which is
based on another different CustomMasterPage3 etc.
So instead of 1 CustomContentPlaceHolders you are suggesting multiple
CustomMasterPages ?  I don't even want to think about it.

I stick by my intern comment - I see no valid reason to not be able to use a
custom ContentPlaceHolder  the same way we would use any other custom
control, say a custom Panel.
Even if someone did come with a 'valid' reason it would in all likelihood
still come down to trying to justify simply bad design.


Show quoteHide quote
"Registered User" <n4***@ix.netcom.com> wrote in message
news:0ra545dn8vfqt7fggm7i9efl7t6ugu2gin@4ax.com...
> On Wed, 24 Jun 2009 12:03:47 -0400, "gerry" <germ2@newsgroup.nospam>
> wrote:
>
>>Sounds like we are SOL on this one due to some 'by design' bug in the
>>designer.
>>My guess is that the master page designer was created by an entry level
>>summer intern who never saw any reason for anyone to ever derive a custom
>>placeholder and accordingly they made sure that you couldn't.
>>
> Abstractly a nested master page can be considered as a custom
> ContentPlaceHolder. Depending upon your needs this might be the way to
> go.
> http://msdn.microsoft.com/en-us/library/x2b3ktt7.aspx
> If so you might want to reconsider the entry level summer intern
> comment.
>
> regards
> A.G.
Author
25 Jun 2009 7:43 PM
Registered User
Show quote Hide quote
On Thu, 25 Jun 2009 13:12:37 -0400, "gerry" <germ2@newsgroup.nospam>
wrote:

>Sorry, but I am not seeing the relevance.
>While that may or may not be true abstractly, concretely it would be a
>design
>& maintenance nightmare.
>
>Where one can simply drop multiple CustomContentPlaceHolders on a MasterPage
>,
>a similar scheme using nested masterpaged would involve basing a MasterPage
>on a CustomMasterPage which is based on different CustomMasterPage2 which is
>based on another different CustomMasterPage3 etc.
>So instead of 1 CustomContentPlaceHolders you are suggesting multiple
>CustomMasterPages ?  I don't even want to think about it.
>
Well I admit I'm unaware of your specific needs.

>I stick by my intern comment - I see no valid reason to not be able to use a
>custom ContentPlaceHolder  the same way we would use any other custom
>control, say a custom Panel.

One reason might be the functionality of the types and their base
classes (Control vs. WebControl) and the fact that ContentPlaceHolder
implements the INamingContainer interface.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.contentplaceholder.aspx
"A ContentPlaceHolder control defines a relative region for content
in a master page, and renders all text, markup, and server controls
from a related Content control found in a content page."
That doesn't describe any type derived from the WebControl class.

And of course it doesn't explain the issues with deriving a type from
the ContentPlaceHolder type.

>Even if someone did come with a 'valid' reason it would in all likelihood
>still come down to trying to justify simply bad design.
>
I can't call it a bad design without understanding the additional
functionality the derived type will bring. Perhaps that functionality
could be provided by using Extension methods eliminating the need to
derive from the ContentPlaceHolder type.
http://msdn.microsoft.com/en-us/library/bb383977.aspx

If the intent is to add default content within the custom type
consider the behavior of the base class.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.contentplaceholder.aspx
"You can specify default content placed within the ContentPlaceHolder
control tags, but this content is replaced by any content in an
associated content page."

The intern comment denigrates the efforts of everyone involved in the
design and production of the .NET framework.

regards
A.G.

Show quoteHide quote
>
>"Registered User" <n4***@ix.netcom.com> wrote in message
>news:0ra545dn8vfqt7fggm7i9efl7t6ugu2gin@4ax.com...
>> On Wed, 24 Jun 2009 12:03:47 -0400, "gerry" <germ2@newsgroup.nospam>
>> wrote:
>>
>>>Sounds like we are SOL on this one due to some 'by design' bug in the
>>>designer.
>>>My guess is that the master page designer was created by an entry level
>>>summer intern who never saw any reason for anyone to ever derive a custom
>>>placeholder and accordingly they made sure that you couldn't.
>>>
>> Abstractly a nested master page can be considered as a custom
>> ContentPlaceHolder. Depending upon your needs this might be the way to
>> go.
>> http://msdn.microsoft.com/en-us/library/x2b3ktt7.aspx
>> If so you might want to reconsider the entry level summer intern
>> comment.
>>
>> regards
>> A.G.
>
>
Author
25 Jun 2009 8:40 PM
gerry
Show quote Hide quote
"Registered User" <n4***@ix.netcom.com> wrote in message
news:9of745ptpc3770b9b0l4avnho1n0bqtvuj@4ax.com...
> On Thu, 25 Jun 2009 13:12:37 -0400, "gerry" <germ2@newsgroup.nospam>
> wrote:
>
>>Sorry, but I am not seeing the relevance.
>>While that may or may not be true abstractly, concretely it would be a
>>design
>>& maintenance nightmare.
>>
>>Where one can simply drop multiple CustomContentPlaceHolders on a
>>MasterPage
>>,
>>a similar scheme using nested masterpaged would involve basing a
>>MasterPage
>>on a CustomMasterPage which is based on different CustomMasterPage2 which
>>is
>>based on another different CustomMasterPage3 etc.
>>So instead of 1 CustomContentPlaceHolders you are suggesting multiple
>>CustomMasterPages ?  I don't even want to think about it.
>>
> Well I admit I'm unaware of your specific needs.
>
>>I stick by my intern comment - I see no valid reason to not be able to use
>>a
>>custom ContentPlaceHolder  the same way we would use any other custom
>>control, say a custom Panel.
>
> One reason might be the functionality of the types and their base
> classes (Control vs. WebControl)

PlaceHolder & UpdatePanel are also Control based and custom versions work
fine.

> and the fact that ContentPlaceHolder
> implements the INamingContainer interface.

as do Panel , PlaceHolder , View , ListView , Repeater , UpdatePanel , ...
custom versions each work fine

Show quoteHide quote
> http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.contentplaceholder.aspx
> "A ContentPlaceHolder control defines a relative region for content
> in a master page, and renders all text, markup, and server controls
> from a related Content control found in a content page."
> That doesn't describe any type derived from the WebControl class.
>
> And of course it doesn't explain the issues with deriving a type from
> the ContentPlaceHolder type.
>
>>Even if someone did come with a 'valid' reason it would in all likelihood
>>still come down to trying to justify simply bad design.
>>
> I can't call it a bad design without understanding the additional
> functionality the derived type will bring.

ok - now you are espousing exactly the mind set that I expect is at the
bottom of this issue, that being, that if you, the designer/developer, can't
think of a reason why you would want to derive from a type then you make
sure that nobody can else derive from that type even if they do have a
perfectly good reason to.

> Perhaps that functionality
> could be provided by using Extension methods eliminating the need to
> derive from the ContentPlaceHolder type.
> http://msdn.microsoft.com/en-us/library/bb383977.aspx
>
> If the intent is to add default content within the custom type
> consider the behavior of the base class.
> http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.contentplaceholder.aspx
> "You can specify default content placed within the ContentPlaceHolder
> control tags, but this content is replaced by any content in an
> associated content page."

although it is irrelevant to the discussion of this undocumented 'feature'
of the ContentPlaceHolder, in this particular case, the intent was to
override the Render method to capture the rendered content, but I'm sure
there are any number of valid reasons.

>
> The intern comment denigrates the efforts of everyone involved in the
> design and production of the .NET framework.

The comment wasn't directed at the designers/developers of the .NET
framework, just the designer/developer of the web form designer , and if the
shoe fits ...

If the ContentPlaceHolder was intentionally meant to be unusable as a base
class then it should have been sealed.
It also worth noting that the custom ContentPlaceHolder control works just
fine at runtime, this a 100% designer issue.


Show quoteHide quote
>
> regards
> A.G.
>
>>
>>"Registered User" <n4***@ix.netcom.com> wrote in message
>>news:0ra545dn8vfqt7fggm7i9efl7t6ugu2gin@4ax.com...
>>> On Wed, 24 Jun 2009 12:03:47 -0400, "gerry" <germ2@newsgroup.nospam>
>>> wrote:
>>>
>>>>Sounds like we are SOL on this one due to some 'by design' bug in the
>>>>designer.
>>>>My guess is that the master page designer was created by an entry level
>>>>summer intern who never saw any reason for anyone to ever derive a
>>>>custom
>>>>placeholder and accordingly they made sure that you couldn't.
>>>>
>>> Abstractly a nested master page can be considered as a custom
>>> ContentPlaceHolder. Depending upon your needs this might be the way to
>>> go.
>>> http://msdn.microsoft.com/en-us/library/x2b3ktt7.aspx
>>> If so you might want to reconsider the entry level summer intern
>>> comment.
>>>
>>> regards
>>> A.G.
>>
>>
Author
26 Jun 2009 1:16 AM
Registered User
Show quote Hide quote
On Thu, 25 Jun 2009 16:40:20 -0400, "gerry" <germ2@newsgroup.nospam>
wrote:
>
>"Registered User" <n4***@ix.netcom.com> wrote in message
>news:9of745ptpc3770b9b0l4avnho1n0bqtvuj@4ax.com...
>> On Thu, 25 Jun 2009 13:12:37 -0400, "gerry" <germ2@newsgroup.nospam>
>> wrote:
>>

>
>although it is irrelevant to the discussion of this undocumented 'feature'
>of the ContentPlaceHolder, in this particular case, the intent was to
>override the Render method to capture the rendered content, but I'm sure
>there are any number of valid reasons.
>
Can the content actually be captured in the derived class' overridden
Render method without infinite recursion?
>>
>> The intern comment denigrates the efforts of everyone involved in the
>> design and production of the .NET framework.
>
>The comment wasn't directed at the designers/developers of the .NET
>framework, just the designer/developer of the web form designer , and if the
>shoe fits ...
>
There are many reviews between conceptualization and release. No one
individual or small group is given free rein to do what they think is
best with no oversight. There are constraints which are unknown to us
and hopefully these constraints will be designed out of future
versions of the tools. In the meantime you're painting with a broad
brush.

>If the ContentPlaceHolder was intentionally meant to be unusable as a base
>class then it should have been sealed.
>It also worth noting that the custom ContentPlaceHolder control works just
>fine at runtime, this a 100% designer issue.
>
Yes there is a designer issue and it has been acknowledged. Knowing
what you're trying to do makes the real question; is a derived
ContentPlaceHolder necessary to capture the content? Add an
OnPreRender event handler to a ContentPlaceHolder instance. Put the
code below into the handler and make the appropriate change to
control's ID.

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            ContentPlaceHolder1.RenderControl(htw);
            string s = sb.ToString();

The string s will contain the ContentPlaceHolder's content. If the
content can be captured without using a derived class, does the valid
reason to derive a class still exist? Explaining what the real task
actually is can lead to simpler/unconsidered solutions. Hopefully this
solution is suitable for your needs.

regards
A.G.
Author
26 Jun 2009 2:40 PM
gerry
Show quote Hide quote
"Registered User" <n4***@ix.netcom.com> wrote in message
news:dc6845h9vsvegbtp53dffbs1tv42o8h9im@4ax.com...
> On Thu, 25 Jun 2009 16:40:20 -0400, "gerry" <germ2@newsgroup.nospam>
> wrote:
>>
>>"Registered User" <n4***@ix.netcom.com> wrote in message
>>news:9of745ptpc3770b9b0l4avnho1n0bqtvuj@4ax.com...
>>> On Thu, 25 Jun 2009 13:12:37 -0400, "gerry" <germ2@newsgroup.nospam>
>>> wrote:
>>>
>
>>
>>although it is irrelevant to the discussion of this undocumented 'feature'
>>of the ContentPlaceHolder, in this particular case, the intent was to
>>override the Render method to capture the rendered content, but I'm sure
>>there are any number of valid reasons.
>>
> Can the content actually be captured in the derived class' overridden
> Render method without infinite recursion?

why not - where do you see recursion in this ?

    protected override void Render(HtmlTextWriter writer)
    {
        StringBuilder sb = new StringBuilder();
        StringWriter sw = new StringWriter(sb);
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        base .Render(htw);

        string content= sb.ToString();

        writer.write(content);

        // ... do whatever else with content
    }

Show quoteHide quote
>>>
>>> The intern comment denigrates the efforts of everyone involved in the
>>> design and production of the .NET framework.
>>
>>The comment wasn't directed at the designers/developers of the .NET
>>framework, just the designer/developer of the web form designer , and if
>>the
>>shoe fits ...
>>
> There are many reviews between conceptualization and release. No one
> individual or small group is given free rein to do what they think is
> best with no oversight. There are constraints which are unknown to us
> and hopefully these constraints will be designed out of future
> versions of the tools. In the meantime you're painting with a broad
> brush.

Some things slip through, especially when noone has thought to test for
them.
But more to the point, poor ( short-sighted ) design - case in point , the
framework classes that started out as either internal or sealed or both in
earlier releases that were eventually made public and/or unsealed because
there actually were valid reasons for it.

Show quoteHide quote
>
>>If the ContentPlaceHolder was intentionally meant to be unusable as a base
>>class then it should have been sealed.
>>It also worth noting that the custom ContentPlaceHolder control works just
>>fine at runtime, this a 100% designer issue.
>>
> Yes there is a designer issue and it has been acknowledged. Knowing
> what you're trying to do makes the real question; is a derived
> ContentPlaceHolder necessary to capture the content? Add an
> OnPreRender event handler to a ContentPlaceHolder instance. Put the
> code below into the handler and make the appropriate change to
> control's ID.
>
>            StringBuilder sb = new StringBuilder();
>            StringWriter sw = new StringWriter(sb);
>            HtmlTextWriter htw = new HtmlTextWriter(sw);
>            ContentPlaceHolder1.RenderControl(htw);
>            string s = sb.ToString();
>

calling render before PreRender has completed or PreRenderComplete has
executed and knowing that PreRender will be called again in the proper
request event sequence sounds pretty hoky.
did you even try this ?
I did - any server controls contained in the ContentPlaceHolder will barf
with a "must be placed inside a form tag with runat=server. " error - not
surprising.
My guess is that any databound controls would also have problems with being
rendered twice - that is if they could get past issue just stated.

> The string s will contain the ContentPlaceHolder's content.

No it won't.

> If the content can be captured without using a derived class, does the
> valid
> reason to derive a class still exist?

Who knows, I don't pretend to know every possible reason for deriving such a
custom control.

> Explaining what the real task actually is can lead to simpler/unconsidered
> solutions.
> Hopefully this solution is suitable for your needs.

Nope

Show quoteHide quote
>
> regards
> A.G.
Author
26 Jun 2009 4:08 PM
Registered User
Show quote Hide quote
On Fri, 26 Jun 2009 10:40:32 -0400, "gerry" <germ2@newsgroup.nospam>
wrote:

>
>"Registered User" <n4***@ix.netcom.com> wrote in message
>news:dc6845h9vsvegbtp53dffbs1tv42o8h9im@4ax.com...
>> On Thu, 25 Jun 2009 16:40:20 -0400, "gerry" <germ2@newsgroup.nospam>
>> wrote:
>>>
>>>"Registered User" <n4***@ix.netcom.com> wrote in message
>>>news:9of745ptpc3770b9b0l4avnho1n0bqtvuj@4ax.com...
>>>> On Thu, 25 Jun 2009 13:12:37 -0400, "gerry" <germ2@newsgroup.nospam>
>>>> wrote:
>>>>
>>
>>>
>>>although it is irrelevant to the discussion of this undocumented 'feature'
>>>of the ContentPlaceHolder, in this particular case, the intent was to
>>>override the Render method to capture the rendered content, but I'm sure
>>>there are any number of valid reasons.
>>>
>> Can the content actually be captured in the derived class' overridden
>> Render method without infinite recursion?
>
>why not - where do you see recursion in this ?
>
>    protected override void Render(HtmlTextWriter writer)
>    {
>        StringBuilder sb = new StringBuilder();
>        StringWriter sw = new StringWriter(sb);
>        HtmlTextWriter htw = new HtmlTextWriter(sw);
>        base .Render(htw);
>
>        string content= sb.ToString();
>
>        writer.write(content);
>
>        // ... do whatever else with content
>    }
>
I was asking a question not saying there would be recursion.

Show quoteHide quote
>>>>
>>>> The intern comment denigrates the efforts of everyone involved in the
>>>> design and production of the .NET framework.
>>>
>>>The comment wasn't directed at the designers/developers of the .NET
>>>framework, just the designer/developer of the web form designer , and if
>>>the
>>>shoe fits ...
>>>
>> There are many reviews between conceptualization and release. No one
>> individual or small group is given free rein to do what they think is
>> best with no oversight. There are constraints which are unknown to us
>> and hopefully these constraints will be designed out of future
>> versions of the tools. In the meantime you're painting with a broad
>> brush.
>
>Some things slip through, especially when noone has thought to test for
>them.
>But more to the point, poor ( short-sighted ) design - case in point , the
>framework classes that started out as either internal or sealed or both in
>earlier releases that were eventually made public and/or unsealed because
>there actually were valid reasons for it.
>
>>
>>>If the ContentPlaceHolder was intentionally meant to be unusable as a base
>>>class then it should have been sealed.
>>>It also worth noting that the custom ContentPlaceHolder control works just
>>>fine at runtime, this a 100% designer issue.
>>>
>> Yes there is a designer issue and it has been acknowledged. Knowing
>> what you're trying to do makes the real question; is a derived
>> ContentPlaceHolder necessary to capture the content? Add an
>> OnPreRender event handler to a ContentPlaceHolder instance. Put the
>> code below into the handler and make the appropriate change to
>> control's ID.
>>
>>            StringBuilder sb = new StringBuilder();
>>            StringWriter sw = new StringWriter(sb);
>>            HtmlTextWriter htw = new HtmlTextWriter(sw);
>>            ContentPlaceHolder1.RenderControl(htw);
>>            string s = sb.ToString();
>>
>
>calling render before PreRender has completed or PreRenderComplete has
>executed and knowing that PreRender will be called again in the proper
>request event sequence sounds pretty hoky.
>did you even try this ?
Yes and the OnPreRender event is only fired once.

>I did - any server controls contained in the ContentPlaceHolder will barf
>with a "must be placed inside a form tag with runat=server. " error - not
>surprising.
I did not experience any problems with this using VS2008.

>My guess is that any databound controls would also have problems with being
>rendered twice - that is if they could get past issue just stated.
>
I did not try databound controls so I won't make any guesses about
rendering the same databound control twice, each time to a different
stream. What impact to the databinding is expected when a control is
rendered twice to different streams?

Admittedly the OnPreRender event may not be the most suitable
location. The same code could be placed in the master page's Page_Load
method. In the example shown at the link below the databound control
gets rendered twice with no issues.
http://www.4guysfromrolla.com/articles/091102-1.aspx


>> The string s will contain the ContentPlaceHolder's content.
>
>No it won't.
>
I did try it using server controls and the string was as expected with
no errors.

>> If the content can be captured without using a derived class, does the
>> valid
>> reason to derive a class still exist?
>
>Who knows, I don't pretend to know every possible reason for deriving such a
>custom control.
>
Re-read the the sentence again and note the explicit reason of
capturing content.

>> Explaining what the real task actually is can lead to simpler/unconsidered
>> solutions.

>> Hopefully this solution is suitable for your needs.
>
>Nope
>
I've tried and apparently failed to explain that a custom
ContentPlaceHolder is not required to accomplish the task. If you feel
it is necessary to use a ContentPlaceHolder-derived type to capture
the content then do it and deal with the designer issue. If the
designer issue shows itself to be an obstacle, you may want to
reconsider possible alternatives.

regards
A.G.

Show quoteHide quote
>>
>> regards
>> A.G.
>
Author
26 Jun 2009 8:41 PM
gerry
attached is a simple project with a master page containing a single
ContentPlaceHolder
and a ContentPage that places a single textbox in the ContentPlaceHolder

trying to capture the generated ContentPlaceHolder content in the
ContentPlaceHolder1_PreRender , Page_Load or Page_PreRenderComplete
all generate the same "must be placed inside a form tag with runat=server. "
error.

I must be doing something wrong if you can do this without any errors - any
idea what ?


Show quoteHide quote
"Registered User" <n4***@ix.netcom.com> wrote in message
news:dqo945h50ptslgv40qv7ocqv9j0mapr0u2@4ax.com...
> On Fri, 26 Jun 2009 10:40:32 -0400, "gerry" <germ2@newsgroup.nospam>
> wrote:
>
>>
>>"Registered User" <n4***@ix.netcom.com> wrote in message
>>news:dc6845h9vsvegbtp53dffbs1tv42o8h9im@4ax.com...
>>> On Thu, 25 Jun 2009 16:40:20 -0400, "gerry" <germ2@newsgroup.nospam>
>>> wrote:
>>>>
>>>>"Registered User" <n4***@ix.netcom.com> wrote in message
>>>>news:9of745ptpc3770b9b0l4avnho1n0bqtvuj@4ax.com...
>>>>> On Thu, 25 Jun 2009 13:12:37 -0400, "gerry" <germ2@newsgroup.nospam>
>>>>> wrote:
>>>>>
>>>
>>>>
>>>>although it is irrelevant to the discussion of this undocumented
>>>>'feature'
>>>>of the ContentPlaceHolder, in this particular case, the intent was to
>>>>override the Render method to capture the rendered content, but I'm sure
>>>>there are any number of valid reasons.
>>>>
>>> Can the content actually be captured in the derived class' overridden
>>> Render method without infinite recursion?
>>
>>why not - where do you see recursion in this ?
>>
>>    protected override void Render(HtmlTextWriter writer)
>>    {
>>        StringBuilder sb = new StringBuilder();
>>        StringWriter sw = new StringWriter(sb);
>>        HtmlTextWriter htw = new HtmlTextWriter(sw);
>>        base .Render(htw);
>>
>>        string content= sb.ToString();
>>
>>        writer.write(content);
>>
>>        // ... do whatever else with content
>>    }
>>
> I was asking a question not saying there would be recursion.

And I was asking in case you see something that I don't.

Show quoteHide quote
>
>>>>>
>>>>> The intern comment denigrates the efforts of everyone involved in the
>>>>> design and production of the .NET framework.
>>>>
>>>>The comment wasn't directed at the designers/developers of the .NET
>>>>framework, just the designer/developer of the web form designer , and if
>>>>the
>>>>shoe fits ...
>>>>
>>> There are many reviews between conceptualization and release. No one
>>> individual or small group is given free rein to do what they think is
>>> best with no oversight. There are constraints which are unknown to us
>>> and hopefully these constraints will be designed out of future
>>> versions of the tools. In the meantime you're painting with a broad
>>> brush.
>>

>>> OnPreRender event handler to a ContentPlaceHolder instance. Put the
>>> code below into the handler and make the appropriate change to
>>> control's ID.
>>>
>>>            StringBuilder sb = new StringBuilder();
>>>            StringWriter sw = new StringWriter(sb);
>>>            HtmlTextWriter htw = new HtmlTextWriter(sw);
>>>            ContentPlaceHolder1.RenderControl(htw);
>>>            string s = sb.ToString();
>>>
>>
>>calling render before PreRender has completed or PreRenderComplete has
>>executed and knowing that PreRender will be called again in the proper
>>request event sequence sounds pretty hoky.
>>did you even try this ?
> Yes and  the OnPreRender event is only fired once.

Typo there - should have been Render will be called again.

Show quoteHide quote
>
>>I did - any server controls contained in the ContentPlaceHolder will barf
>>with a "must be placed inside a form tag with runat=server. " error - not
>>surprising.
> I did not experience any problems with this using VS2008.
>
>>My guess is that any databound controls would also have problems with
>>being
>>rendered twice - that is if they could get past issue just stated.
>>
> I did not try databound controls so I won't make any guesses about
> rendering the same databound control twice, each time to a different
> stream. What impact to the databinding is expected when a control is
> rendered twice to different streams?
>
> Admittedly the OnPreRender event may not be the most suitable
> location. The same code could be placed in the master page's Page_Load
> method. In the example shown at the link below the databound control
> gets rendered twice with no issues.
> http://www.4guysfromrolla.com/articles/091102-1.aspx

and that article also links to a second article because it only works with
pre 2.0 versions of the framework.
the method generates errors in 2.0+ - he did run into a different error so
there are obviously multiple problems with this solution
calling the Render method at any time before the Page_PreRenderComplete has
fired could generate invalid results due to code in the contained controls
PreRender that will not have had a chance to fire.

Show quoteHide quote
>
>
>>> The string s will contain the ContentPlaceHolder's content.
>>
>>No it won't.
>>
> I did try it using server controls and the string was as expected with
> no errors.
>
>>> If the content can be captured without using a derived class, does the
>>> valid
>>> reason to derive a class still exist?
>>
>>Who knows, I don't pretend to know every possible reason for deriving such
>>a
>>custom control.
>>
> Re-read the the sentence again and note the explicit reason of
> capturing content.

You are assuming that this is the only reason we wanted to do this or the
only reason that others may want to do this.

Show quoteHide quote
>
>>> Explaining what the real task actually is can lead to
>>> simpler/unconsidered
>>> solutions.
>
>>> Hopefully this solution is suitable for your needs.
>>
>>Nope
>>
> I've tried and apparently failed to explain that a custom
> ContentPlaceHolder is not required to accomplish the task. If you feel
> it is necessary to use a ContentPlaceHolder-derived type to capture
> the content then do it and deal with the designer issue. If the
> designer issue shows itself to be an obstacle, you may want to
> reconsider possible alternatives.

We are pretty much giving up on this for now.

>
> regards
> A.G.
>
>>>
>>> regards
>>> A.G.
>>

[attached file: OnPreRender.zip]
Author
27 Jun 2009 4:01 PM
Registered User
Show quote Hide quote
On Fri, 26 Jun 2009 16:41:34 -0400, "gerry" <germ2@newsgroup.nospam>
wrote:

>attached is a simple project with a master page containing a single
>ContentPlaceHolder
>and a ContentPage that places a single textbox in the ContentPlaceHolder
>
>trying to capture the generated ContentPlaceHolder content in the
>ContentPlaceHolder1_PreRender , Page_Load or Page_PreRenderComplete
>all generate the same "must be placed inside a form tag with runat=server. "
>error.
>
>I must be doing something wrong if you can do this without any errors - any
>idea what ?
>
You used the wrong server control. No, seriously I used a label in my
quickie test.
-snip -
>>>
>> I was asking a question not saying there would be recursion.
>
>And I was asking in case you see something that I don't.
>
-snip -
>> Yes and  the OnPreRender event is only fired once.
>
>Typo there - should have been Render will be called again.
No problem with it being a typo. These things happen.
>
>>
- snip -
>> http://www.4guysfromrolla.com/articles/091102-1.aspx
>
>and that article also links to a second article because it only works with
>pre 2.0 versions of the framework.
>the method generates errors in 2.0+ - he did run into a different error so
>there are obviously multiple problems with this solution
>calling the Render method at any time before the Page_PreRenderComplete has
>fired could generate invalid results due to code in the contained controls
>PreRender that will not have had a chance to fire.
>
I scanned the article quickly as I've got my own managers trying to
boil the ocean.
- snip -
>>
>>>> Hopefully this solution is suitable for your needs.
>>>
>>>Nope
>>>
And now I see why it's not suitable and understand your frustration
with a derived ContentPlaceHolder type's behavior.

>> I've tried and apparently failed to explain that a custom
>> ContentPlaceHolder is not required to accomplish the task. If you feel
>> it is necessary to use a ContentPlaceHolder-derived type to capture
>> the content then do it and deal with the designer issue. If the
>> designer issue shows itself to be an obstacle, you may want to
>> reconsider possible alternatives.
>
I should have written "may not be required".

>We are pretty much giving up on this for now.
>
I try to avoid asking the 'why' question because too often the
question is taken as a personal affront. The question isn't really
about an 'requirement' being good or bad as much as 'is it really a
necessary requirement?' That question would be in my mind even if a
derived ContentPlaceHolder worked as it should in the designer.

Sometimes not doing something can be a viable alternative. This might
be suitable for you situation or maybe nested master pages. Another
option might be to put each ContentPlaceHolder inside of a div,
capture the entire page's content, and then parse the content for the
divs using a DOM. I'm not saying this would work but you might want to
try it and see depending upon the status of the requirement.

I appreciate the time you've taken to explain the issues you've run up
against. Hopefully that time is billable ;)

regards
A.G.
Author
27 Jun 2009 5:10 PM
gerry
Show quote Hide quote
"Registered User" <n4***@ix.netcom.com> wrote in message
news:pdac45dtefj1jjv19lcptrkq27lvn8638i@4ax.com...
> On Fri, 26 Jun 2009 16:41:34 -0400, "gerry" <germ2@newsgroup.nospam>
> wrote:
>
....

>
>>We are pretty much giving up on this for now.
>>
> I try to avoid asking the 'why' question because too often the
> question is taken as a personal affront. The question isn't really
> about an 'requirement' being good or bad as much as 'is it really a
> necessary requirement?' That question would be in my mind even if a
> derived ContentPlaceHolder worked as it should in the designer.
>
> Sometimes not doing something can be a viable alternative. This might
> be suitable for you situation or maybe nested master pages. Another
> option might be to put each ContentPlaceHolder inside of a div,

Actually we did get this to work by wrapping the ContentPlaceHolder in the
master page within a custom Panel. It requires an additional bit of markup
per placeholder but it lets us encapsulate the required functionality within
one control and it works.

Show quoteHide quote
> capture the entire page's content, and then parse the content for the
> divs using a DOM. I'm not saying this would work but you might want to
> try it and see depending upon the status of the requirement.
>
> I appreciate the time you've taken to explain the issues you've run up
> against. Hopefully that time is billable ;)
>
> regards
> A.G.
>
>

Bookmark and Share