473,387 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
ma******@gmail.com

Jul 19 '06 #1
2 1701
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
ma******@gmail.com
Jul 19 '06 #2
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
ma******@gmail.com
Jul 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Amilcar | last post by:
Hi: I have a problem: I've a page that sends an encrypted password, using MD5, to a PHP file, which is able to compare such MD5 encrypted password with an encryption stored on a data base. But...
0
by: Ronan | last post by:
Hi, I have a problem with a form using the PHP PEAR HTML_QuickForm package & javascript: I want to record the content of my form into a mySQL database then execute a javascript function. ...
9
by: Bart Nessux | last post by:
I am using method 'a' below to pick 25 names from a pool of 225. A co-worker is using method 'b' by running it 25 times and throwing out the winning name (names are associated with numbers) after...
5
by: Florian Proch | last post by:
Hi all... i'm currently working for a big project to construct a website. We need to support some browser and OS : IE 5.0 -> IE 6, Mozilla 1.2 -> 1.7, Opera 5 -> Opéra 7.5x, Netscape 4.75 -> NS...
2
by: Nathan Sokalski | last post by:
As most Javascript coders probably know by now, IE on Windows XP SP2 likes to prevent our code from running right away (the user is asked to give permission the first time). Although I can see the...
6
by: b.dam | last post by:
I'm trying to do the following: function row() { this.selected = false; this._el = document.createElement("TR"); this._el.attachEvent("onClick", this.rowClick); } row.prototype.rowClick =...
2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added...
4
by: MW | last post by:
How can I poplute a javascript array from vb.net? I would prefer to do this from codebehind. Michael
5
by: Nike1984 | last post by:
I'm fairly new to Javascript and it's more of a guessing game for me... I'm trying to build an app for Google Maps and just had some issues recently. First off I just wanted to say that everything...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.