Re: Custom ContentPlaceHolder
- From: Registered User <n4jvp@xxxxxxxxxxxxx>
- Date: Fri, 26 Jun 2009 12:08:22 -0400
On Fri, 26 Jun 2009 10:40:32 -0400, "gerry" <germ2@xxxxxxxxxxxxxxxx>
wrote:
I was asking a question not saying there would be recursion.
"Registered User" <n4jvp@xxxxxxxxxxxxx> wrote in message
news:dc6845h9vsvegbtp53dffbs1tv42o8h9im@xxxxxxxxxx
On Thu, 25 Jun 2009 16:40:20 -0400, "gerry" <germ2@xxxxxxxxxxxxxxxx>
wrote:
"Registered User" <n4jvp@xxxxxxxxxxxxx> wrote in message
news:9of745ptpc3770b9b0l4avnho1n0bqtvuj@xxxxxxxxxx
On Thu, 25 Jun 2009 13:12:37 -0400, "gerry" <germ2@xxxxxxxxxxxxxxxx>
wrote:
Can the content actually be captured in the derived class' overridden
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.
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
}
Yes and the OnPreRender event is only fired once.There are many reviews between conceptualization and release. No one
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 ...
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 baseYes there is a designer issue and it has been acknowledged. Knowing
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.
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 barfI did not experience any problems with this using VS2008.
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 beingI did not try databound controls so I won't make any guesses about
rendered twice - that is if they could get past issue just stated.
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
I did try it using server controls and the string was as expected withThe string s will contain the ContentPlaceHolder's content.
No it won't.
no errors.
Re-read the the sentence again and note the explicit reason ofIf 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.
capturing content.
Explaining what the real task actually is can lead to simpler/unconsidered
solutions.
I've tried and apparently failed to explain that a customHopefully this solution is suitable for your needs.
Nope
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.
.
regards
A.G.
- References:
- RE: Custom ContentPlaceHolder
- From: Allen Chen [MSFT]
- RE: Custom ContentPlaceHolder
- From: fruitbatinshades
- Re: Custom ContentPlaceHolder
- From: gerry
- Re: Custom ContentPlaceHolder
- From: Registered User
- Re: Custom ContentPlaceHolder
- From: gerry
- Re: Custom ContentPlaceHolder
- From: Registered User
- Re: Custom ContentPlaceHolder
- From: gerry
- Re: Custom ContentPlaceHolder
- From: Registered User
- Re: Custom ContentPlaceHolder
- From: gerry
- RE: Custom ContentPlaceHolder
- Prev by Date: Boundfield display value
- Next by Date: Re: Boundfield display value
- Previous by thread: Re: Custom ContentPlaceHolder
- Next by thread: Re: Custom ContentPlaceHolder
- Index(es):
Relevant Pages
|
Loading