Re: javascript within Custom Web Control

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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 .



Relevant Pages

  • Re: No scroll bar for page + page error(s)
    ... that the javascript in the head preloads ... An error has occurred in the script on this page ... >>FrontPage Resources, WebCircle, MS KB Quick Links, etc. ...
    (microsoft.public.frontpage.client)
  • Re: Help with space mysterous small spacing gltich
    ... javascript for old browsers, ... declaration, a head, a title in the head and so on.... ... It's actually not for a website, it's for an eBay auction template, so the whole top section get stripped, so I didn't include it. ...
    (alt.html)
  • Re: Beginning JS
    ... I have my head around the basic concepts and can ... write small scripts but I don't really, currently, have the opportunity ... See if you can write the solution code on your own (research is allowed, but reading followup posts won't help you). ... The best place to learn Javascript? ...
    (comp.lang.javascript)
  • Re: [PHP] A two flavored post
    ... var someLink = document.getElementById; ... I asked this question on the javascript list, ... html statement: ...
    (php.general)
  • Re: Insert Page is not working properly
    ... I would leave it in the body of the include, and remove it from the head section of the main page. ... javascript goes in menu.htm body. ... > necessary header info in the headers of all the pages using the menu. ...
    (microsoft.public.frontpage.client)