Reputation: 1740
I have a situation where in I am adding .js file to my aspx page using content place holder. I need to add all the js to end of the page(the said content place holder is at bottom of the master page)
Here's the code for the same
ContentPlaceHolder content = (ContentPlaceHolder)Page.Master.FindControl("additionalJavaScript");
content.Controls.Add(new DeferedMinifiedScript("~/Scripts/Controls/ListBoxControl.js"));
Now the issue is I need to add the ListBoxControl.js file only once on the page. But this is adding the file everytime a new listbox control is rendered on the page.
I need to put a check in place to see if the file is already available as control on page then skip adding it again.
I tried the following
var abc = new DeferedMinifiedScript("~/Scripts/Controls/ListBoxControl.js");
if(content.Controls.Contains(abc))
{
//Don't add the file again.
}
But this is still adding the file again and again.
Is there a way out?
Also, I can't use RegisterClientScriptInclude or similar functions
Upvotes: 1
Views: 42
Reputation: 3591
You should be able to use this:
and Set the contents to a string and then use string to compare to see if it contains your .js string/path to file, then if it does do not do.
Upvotes: 0