Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Populating DIV tag from javascript via ASP.Net & ClientScript methods

Reply
Thread Tools

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

 
 
Dave Mathew
Guest
Posts: n/a
 
      07-19-2006
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


 
Reply With Quote
 
 
 
 
neilmcguigan@gmail.com
Guest
Posts: n/a
 
      07-19-2006
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
>


 
Reply With Quote
 
 
 
 
Clinton Farleigh
Guest
Posts: n/a
 
      07-20-2006
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
>


 
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
<div ... /> and <div ...></div> K Viltersten ASP .Net 4 03-31-2009 07:33 PM
Select text within a div tag by clicking on content of div tag or a button? visu Javascript 4 11-22-2006 06:25 AM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Q: Div A inside Div B is larger than Div B Dwayne Madsen Javascript 1 06-01-2005 03:02 PM
Select text within a div tag by clicking on content of div tag? M Wells Javascript 0 10-06-2004 11:04 AM



Advertisments