Populating DIV tag from javascript via ASP.Net & ClientScript methods

Discussion in 'ASP .Net' started by Dave Mathew, Jul 20, 2006.

  1. Dave Mathew

    Dave Mathew Guest

    I'm trying to run some clientside javascript on page load for one of my
    ASP.Net pages. I am using the ClientScript.RegisterClient....() methods
    to register an external javascript file within ASP.Net. When I put my
    code on a ASP button and click it it works just find, runs my
    javascript which popus up an alert and then changes the div text.
    However, when I put this on a Page_Load event the alert comes up ok but
    the changing of the div text does not occur. I have a feeling this has
    something to do with not all the page elements being rendered or
    avaiable in some way to the javascript. I've tried placing the code in
    LoadComplete, and Init, with the same results. Any suggestions on how I
    can get my javascript code to be triggered on page load from ASP and be
    able to access page elements like div tags? I don't have my code in
    front of me now but could come up with example if needed. Any advice is
    appreciated.

    David Mathew
     
    Dave Mathew, Jul 20, 2006
    #1
    1. Advertising

  2. Dave Mathew

    Guest

    using masterpages? if so, it changes the client ID


    Dave Mathew wrote:
    > I'm trying to run some clientside javascript on page load for one of my
    > ASP.Net pages. I am using the ClientScript.RegisterClient....() methods
    > to register an external javascript file within ASP.Net. When I put my
    > code on a ASP button and click it it works just find, runs my
    > javascript which popus up an alert and then changes the div text.
    > However, when I put this on a Page_Load event the alert comes up ok but
    > the changing of the div text does not occur. I have a feeling this has
    > something to do with not all the page elements being rendered or
    > avaiable in some way to the javascript. I've tried placing the code in
    > LoadComplete, and Init, with the same results. Any suggestions on how I
    > can get my javascript code to be triggered on page load from ASP and be
    > able to access page elements like div tags? I don't have my code in
    > front of me now but could come up with example if needed. Any advice is
    > appreciated.
    >
    > David Mathew
    >
     
    , Jul 20, 2006
    #2
    1. Advertising

  3. I think what you are running into is the javascript code being executed
    before the elements of your page have been created in the page DOM.
    Try to stick your javascript into the onload attribute of your body tag
    and see if it will work.

    If this does work, I think what you will have to do is register your
    javascript with the onload event either by adding it as an attribute of
    the body tag or via external script.

    http://www.quirksmode.org/js/events_advanced.html

    The above article is similar to what you could use to register your
    javascript with the load event except of course the event you want to
    register for is load (onload in IE) and I believe you want to use
    window as your element.

    I wrote a javascript register function that handles cross browser
    registration a while ago but don't have it with me. Let me know if you
    want it and I'll post it. I believe there are also similar examples
    out there somewhere on the web.

    Clint.

    Dave Mathew wrote:
    > I'm trying to run some clientside javascript on page load for one of my
    > ASP.Net pages. I am using the ClientScript.RegisterClient....() methods
    > to register an external javascript file within ASP.Net. When I put my
    > code on a ASP button and click it it works just find, runs my
    > javascript which popus up an alert and then changes the div text.
    > However, when I put this on a Page_Load event the alert comes up ok but
    > the changing of the div text does not occur. I have a feeling this has
    > something to do with not all the page elements being rendered or
    > avaiable in some way to the javascript. I've tried placing the code in
    > LoadComplete, and Init, with the same results. Any suggestions on how I
    > can get my javascript code to be triggered on page load from ASP and be
    > able to access page elements like div tags? I don't have my code in
    > front of me now but could come up with example if needed. Any advice is
    > appreciated.
    >
    > David Mathew
    >
     
    Clinton Farleigh, Jul 20, 2006
    #3
    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. sck10
    Replies:
    7
    Views:
    7,487
    Steven Cheng[MSFT]
    Nov 17, 2005
  2. shruds
    Replies:
    1
    Views:
    957
    John C. Bollinger
    Jan 27, 2006
  3. =?Utf-8?B?bWFj?=

    Remove clientscript block from page (ASP.NET 1.1)

    =?Utf-8?B?bWFj?=, Jun 13, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    5,976
    Jacob
    Jun 20, 2006
  4. M Wells
    Replies:
    0
    Views:
    151
    M Wells
    Oct 6, 2004
  5. visu
    Replies:
    4
    Views:
    325
Loading...

Share This Page