I've developed a new control which is pretty complex. I also know for a fact that it will not be present on the page the first time it's opened, but only when the user clicks a button to show it (thus, it first appears on a postback). We also use Microsoft's ASP.NET AJAX framework to make all our postbacks partially-updating.
Since the control is pretty complex, it depends on a bunch of javascript files, has it's own CSS file and some images. It would be unreasonable to include those at all times, since it will only be present at a few forms, and even then not always. Also, while currently there is no requirement to host more than one instance of the control, I'd like to keep this option open, otherwise 3 years down the road someone will try to do it and be surprised if it doesn't work.
So how do I make it so, that the CSS/JS files are included only once on the page (even though there might be several such controls), and only on the first request that the control appears there (so that subsequent requests don't try to unnecessarily re-download these resources)?
Page.ClientScript.RegisterClientScriptInclude()
doesn't work on AJAX postbacks; ScriptManager.RegisterClientScriptInclude()
will make the browser re-download the scripts on every request, even though it might have already been downloaded.
And neither of them are usable for CSS including. What else?