문제

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?

도움이 되었습니까?

해결책

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top