Script inside the header tags

E

Erik Cruz

Hi.

I am writing a control that derives from the label control. My control needs
to render some Javascript inside the header tags, but all I get till now is
an script inside the form tags. Can anyone shows me how to insert Javascript
inside the header tags from a custom control?

TIA,
Erik Cruz
 
A

Alex Homer

Just an idea - and a bit ugly - but you might try:

Add a runat="server" attribute to the <head> element and give it an id.
In your control, get a reference to this control through the Page o Parent
object and insert another control into its Controls collection, then set the
Text or InnerHtml to a string containing the script. You might get away with
using a Literal control, or a PlaceHolder, or even a Label...
 
A

Adrian Parker

What I did was to create a usercontrol that I dragged onto the form,
then in the html view moved the <uc1:myjs line into the header section
of the page.

Then in the usercontrol I have..

Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
writer.Write("<script>")
writer.Write("... rest of script ...")
writer.Write("</script>")

Hope that helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,813
Members
47,357
Latest member
sitele8746

Latest Threads

Top