Question

I'm building several user controls (ASCX) for my website and several of them are very similar in what they do. (As a side note, I must create unique UC's even if they're similar because I'm creating widgets for the new Telligent Community themeing system). For example, two of them are different but use the same front-end code to create a 2 or 3 tab panel where you can click a tab and it changes the data below. I have a single JS file to handle these tabs and the animations. I'm currently dynamically adding my JS file reference to the <head> from the user controls' code via:

Literal jsFile = new Literal();
jsFile.Text = string.Format("<script src=\"{0}\"></script>", "/community/themes/test/js/tabbedCallout.js");
Page.Header.Controls.Add(jsFile);

If I have both of these controls on a page though, both will add this JS file reference. How can I do a check to see if it is already added from another control?

Was it helpful?

Solution

Why don't you use Page.ClientScript.RegisterClientScriptBlock (as described here: http://msdn.microsoft.com/en-us/library/btf44dc9.aspx)?
This way you could add a key to each script you need and identify the script by its key!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top