Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > javascript within Custom Web Control

Reply
Thread Tools

javascript within Custom Web Control

 
 
ThunderMusic
Guest
Posts: n/a
 
      01-21-2006
Hi,
I'm making a Custom Web Control and I'm wondering how I can insert
Javascript code into the head part of the document from within my web
control... I lloked at the methods of the HtmlTextWriter output object from
the Render method, but I didn't fiind anything. I have 2 questions :

1. Is it this important to put the javascript code into the head or it can
be in the body without causing trouble?
2. If it is important to put it in <Head>, how can I do it from my Web
Control?

Thanks a lot.

ThunderMusic


 
Reply With Quote
 
 
 
 
Laurent Bugnion
Guest
Posts: n/a
 
      01-21-2006
Hi,

ThunderMusic wrote:
> Hi,
> I'm making a Custom Web Control and I'm wondering how I can insert
> Javascript code into the head part of the document from within my web
> control... I lloked at the methods of the HtmlTextWriter output object from
> the Render method, but I didn't fiind anything. I have 2 questions :
>
> 1. Is it this important to put the javascript code into the head or it can
> be in the body without causing trouble?


It is not vital that JavaScript be placed in the HEAD part of the HTML
page. It is recommended, because the JavaScript parser will ready all
the functions placed there before starting to render the body, but it is
not a must.

Just make sure that your JavaScript code is placed before the call to
it, the best being placing the code in functions, and calling the
functions from an "onload" event of the body tag. Since the "onload"
event is fired only after the whole code (HTML and JavaScript) is parsed
and prepared, you're sure that your JavaScript environment is ready.

> 2. If it is important to put it in <Head>, how can I do it from my Web
> Control?


You can't with the default Page class. When I really have (or want to)
place code in the HEAD part, I use a self-written Custom control which I
use to register headers (CSS files, JavaScript files or code). Not the
most elegant way, but it works.

>
> Thanks a lot.
>
> ThunderMusic


HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom control within a custom control J R M ASP .Net 2 06-01-2006 06:04 PM
Custom control within repeater with custom object binding - .net 1 =?Utf-8?B?SmF5YnVmZmV0?= ASP .Net 9 02-21-2006 03:38 AM
Capturing event from other custom control within another custom control Jonah Olsson ASP .Net 1 04-05-2005 01:39 PM
Capturing event from other custom control within another custom control Jonah Olsson ASP .Net Web Controls 2 04-05-2005 12:56 PM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM



Advertisments