javascript within Custom Web Control

Discussion in 'ASP .Net' started by ThunderMusic, Jan 21, 2006.

  1. ThunderMusic

    ThunderMusic Guest

    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
    ThunderMusic, Jan 21, 2006
    #1
    1. Advertising

  2. 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
    Laurent Bugnion, Jan 21, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonah Olsson
    Replies:
    1
    Views:
    562
    Scott Allen
    Apr 5, 2005
  2. =?Utf-8?B?SmF5YnVmZmV0?=
    Replies:
    9
    Views:
    838
    Phillip Williams
    Feb 21, 2006
  3. J R M
    Replies:
    2
    Views:
    418
    Charlie@CBFC
    Jun 1, 2006
  4. Matt Sokol
    Replies:
    2
    Views:
    365
    Theo Tillotson
    Aug 7, 2003
  5. Jonah Olsson
    Replies:
    2
    Views:
    187
    Jonah Olsson
    Apr 5, 2005
Loading...

Share This Page