954,178 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Modifying head tag of parent file.

Right now, I have a project with a class of a custom control. I also have a project with an .aspx file and its back code that implements the control of my other class.

In the control's class, I need to write code that will add some javascript in the head tag of web pages that will use this control.

I found out that with this code:

System.Web.UI.HtmlControls.HtmlGenericControl a = (System.Web.UI.HtmlControls.HtmlGenericControl)this.Parent.Parent.Controls[1];
a.InnerHtml += "<script type=\"text/javascript\" src=\"" + "file.js\"></script>";


I can do it but I need the users to add runat="server" to the head tag of their pages for it to work.

Does anyone know how I would do this without modifying the aspx file's head tag?

Thank you very much...

belama
Posting Shark
963 posts since Mar 2005
Reputation Points: 19
Solved Threads: 2
 

Can you use the "RegisterClientScriptBlock()" method, instead?

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

I thought of something like that today. It'll also be good to prevent the code from writing to the page more than onece if I have multiple instances of the control.

thanks

belama
Posting Shark
963 posts since Mar 2005
Reputation Points: 19
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You