944,147 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 4410
  • C# RSS
May 17th, 2005
0

Modifying head tag of parent file.

Expand Post »
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:

C# Syntax (Toggle Plain Text)
  1. System.Web.UI.HtmlControls.HtmlGenericControl a = (System.Web.UI.HtmlControls.HtmlGenericControl)this.Parent.Parent.Controls[1];
  2. 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...
Similar Threads
Reputation Points: 19
Solved Threads: 2
Posting Shark
belama is offline Offline
962 posts
since Mar 2005
May 27th, 2005
0

Re: Modifying head tag of parent file.

Can you use the "RegisterClientScriptBlock()" method, instead?
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
May 27th, 2005
0

Re: Modifying head tag of parent file.

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
Reputation Points: 19
Solved Threads: 2
Posting Shark
belama is offline Offline
962 posts
since Mar 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: adding innertext to an xml node
Next Thread in C# Forum Timeline: Problem with sql reader





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC