views:

54

answers:

1

I have a user control that is cached and as part of this control, javascript for loading a swfobject is written to the page. I've tried using ClientScript.RegisterStartupScript to write the javascript to the page, however, when rendered from the cache, the javascript is no longer included. This means the swfobject is not loaded.

Currently I'm writing the script into part of the control's div.InnerHTML, which works, but is there a better way?

+1  A: 

No, as far as I know there is no better way.

You can use a Literal or a PlaceHolder instead of a div to put the code in, so that you don't have the extra div, but other than that it can't really be improved. If you want to cache the control, all that it does has to be included in what it renders to the page. When the controls is rendered from the cache the code behind is not executed, so it can't have any side effects outside of the control itself.

Guffa