Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Rendering HTML Once Per Group of Controls...

Have a custom web control where 1..n controls can be dropped onto a webform.  These are HTML editing controls and the text within the controls can be manipulated via a toolbar that appears at the top of the browser when a user is editing.  They can do the usual bold, italic, etc.

I'm trying to have the toolbar HTML emitted only once to the browser, not for each control.  In other words, if I have three controls on a page I don't want the toolbar code emitted three times to the browser.

I've googled and messed around but I can't figure out how to check on the server side if the toolbar code has already been emitted for the current request.  This seems like a really easy thing to do but it's escaping me for some reason.

Thanks for any pointers.

smallbiz
Tuesday, December 14, 2004

Also...I'm aware of Page.IsClientScriptBlockRegistered but I'm not trying to render JavaScript, just some HTML code that builds a <div> and <table> that is the toolbar.

smallbiz
Tuesday, December 14, 2004

I think you can render HTML using RegisterClientScriptBlock  and RegisterStartupScript, but you can't control where it's rendered, so this may not solve your problem.

Another solution would be to store a flag in Context.Items collection to control whether your stuff has been rendered:

if (Context.Items["MyWebControlHasRendered"] == null)
{
    ... render the stuff here ...
  Context.Items["MyWebControlHasRendered"] = new object();
}

Joe
Tuesday, December 14, 2004

*  Recent Topics

*  Fog Creek Home