473,748 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Execute JavaScript from Page_Load

Is there a way to execute a JavaScript from the Page_Load event?

Or alternatively, is there a way to have it execute when the page is loaded?

I am defining the script in the Page_Load event and using the
RegisterStartup Function to add it to the page. I just need a way to execute
the script when the page loads.

Any ideas?

Thanks in advance,
Scott
Nov 18 '05 #1
5 4931
Look into using the body onload event. This JavaScript event will be fired
once the complete file is sent to the user.

HTH MikeL

"Scott Natwick" wrote:
Is there a way to execute a JavaScript from the Page_Load event?

Or alternatively, is there a way to have it execute when the page is loaded?

I am defining the script in the Page_Load event and using the
RegisterStartup Function to add it to the page. I just need a way to execute
the script when the page loads.

Any ideas?

Thanks in advance,
Scott

Nov 18 '05 #2
Thanks, Mike.

I appreciate the response.

I tried triggering the function from the "onload" event of the "body," like
you suggested.

However, the message I get is " undefined:NaN". I think maybe the timing is
off or somthing?

If I add a button to the page and have the button call the function, it
works.

Any thoughts on this?

Thanks again,
Scott

"MikeL" <Mi***@discussi ons.microsoft.c om> wrote in message
news:22******** *************** ***********@mic rosoft.com...
Look into using the body onload event. This JavaScript event will be
fired
once the complete file is sent to the user.

HTH MikeL

"Scott Natwick" wrote:
Is there a way to execute a JavaScript from the Page_Load event?

Or alternatively, is there a way to have it execute when the page is
loaded?

I am defining the script in the Page_Load event and using the
RegisterStartup Function to add it to the page. I just need a way to
execute
the script when the page loads.

Any ideas?

Thanks in advance,
Scott

Nov 18 '05 #3
Thanks for the response, Mike.

I tried what you suggest. I added the function call to the "onload" event
of the "body."

However, I received the message " undefined:NaN" as a result of the function
call.

I think maybe the timing may be off?

If I trigger the function call from a button, once the page is loaded, it
works.

Any thoughts?

Thanks again,
Scott

"MikeL" <Mi***@discussi ons.microsoft.c om> wrote in message
news:22******** *************** ***********@mic rosoft.com...
Look into using the body onload event. This JavaScript event will be
fired
once the complete file is sent to the user.

HTH MikeL

"Scott Natwick" wrote:
Is there a way to execute a JavaScript from the Page_Load event?

Or alternatively, is there a way to have it execute when the page is
loaded?

I am defining the script in the Page_Load event and using the
RegisterStartup Function to add it to the page. I just need a way to
execute
the script when the page loads.

Any ideas?

Thanks in advance,
Scott

Nov 18 '05 #4
Scott,

It sounds like the JavaScript function is not being loaded onto the page
before the body tag. To see if this is happening save the page as HTML and
open it up in IE. It it works then, then it is a load problem. Try
registering the script in the page load event.

HTH MikeL

"Scott Natwick" wrote:
Thanks for the response, Mike.

I tried what you suggest. I added the function call to the "onload" event
of the "body."

However, I received the message " undefined:NaN" as a result of the function
call.

I think maybe the timing may be off?

If I trigger the function call from a button, once the page is loaded, it
works.

Any thoughts?

Thanks again,
Scott

"MikeL" <Mi***@discussi ons.microsoft.c om> wrote in message
news:22******** *************** ***********@mic rosoft.com...
Look into using the body onload event. This JavaScript event will be
fired
once the complete file is sent to the user.

HTH MikeL

"Scott Natwick" wrote:
Is there a way to execute a JavaScript from the Page_Load event?

Or alternatively, is there a way to have it execute when the page is
loaded?

I am defining the script in the Page_Load event and using the
RegisterStartup Function to add it to the page. I just need a way to
execute
the script when the page loads.

Any ideas?

Thanks in advance,
Scott


Nov 18 '05 #5
Mike,

Thanks very much for your help. You nailed it! It's working now.

Scott

"MikeL" <Mi***@discussi ons.microsoft.c om> wrote in message
news:38******** *************** ***********@mic rosoft.com...
Scott,

It sounds like the JavaScript function is not being loaded onto the page
before the body tag. To see if this is happening save the page as HTML
and
open it up in IE. It it works then, then it is a load problem. Try
registering the script in the page load event.

HTH MikeL

"Scott Natwick" wrote:
Thanks for the response, Mike.

I tried what you suggest. I added the function call to the "onload"
event
of the "body."

However, I received the message " undefined:NaN" as a result of the
function
call.

I think maybe the timing may be off?

If I trigger the function call from a button, once the page is loaded, it
works.

Any thoughts?

Thanks again,
Scott

"MikeL" <Mi***@discussi ons.microsoft.c om> wrote in message
news:22******** *************** ***********@mic rosoft.com...
> Look into using the body onload event. This JavaScript event will be
> fired
> once the complete file is sent to the user.
>
> HTH MikeL
>
> "Scott Natwick" wrote:
>
>> Is there a way to execute a JavaScript from the Page_Load event?
>>
>> Or alternatively, is there a way to have it execute when the page is
>> loaded?
>>
>> I am defining the script in the Page_Load event and using the
>> RegisterStartup Function to add it to the page. I just need a way to
>> execute
>> the script when the page loads.
>>
>> Any ideas?
>>
>> Thanks in advance,
>> Scott
>>
>>
>>


Nov 18 '05 #6

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

Similar topics

2
3019
by: Jim Hammond | last post by:
The script function in the code below works fine when it is JavaScript, but when I try to use C#, the function doesn't get executed. <body MS_POSITIONING="GridLayout"> <form id="Form1" name="Form1" method="post" encType="multipart/form-data" runat="server" VIEWASTEXT> <asp:button id="Button3" runat="server" Text="TAKE PHOTO"></asp:button> </form>
1
1996
by: Michael SL | last post by:
Here is my problem. I have a delete record button. I want to prompt the user "Do you really want to delete?". If the user clicks 'OK' then I want to execute the CodeBehind on the server side to accomplish this. How do I do this I think the HtmlButton is probably the desired method. But, how do I get the client side javascript to execute the desired (when needed) the server side codebehind function?
4
2997
by: Julia | last post by:
Hi Everyone, I am using webbrowser control to post data to an aspx page. However, for some reason, the aspx page sometimes will execute page_load event twice, and sometimes execute it once. So I might get different results for executing it. If I have the webbrwoser control to call it the first time, the aspx will usually execute the page_load twice. What can be the problem?
6
2917
by: Brian Miller | last post by:
I've been constructing an ASP.Net application using the 1.1 framework, and have been using Web Matrix for development purposes. Now that my application is near completion, I wanted to see if I can set up my pages for access directly via localhost (not using the WebMatrix server). My login page loads, and any validation controls on the page work fine, so I know it's recognizing the ASP.Net code there, however, when I try to log on, the...
4
4064
by: Ian Kelly | last post by:
Hi All, I have an .net form that is split into two frames. The left frame has a tree that displays a list of all the customers. The right frame displays the appropriate clients information. When the save button is pressed on the right frame, I want to update the tree in the left frame AFTER saving all the data as the changes to the right frame may affect how the tree is displayed. I tried using the following: ...
4
2795
by: Mark Miller | last post by:
I've been trying to execute a javascript function just before submit on a form that contains an <input type="file"> input field and it isn't working. The reason I want to do this is the end users will be uploading files that are between 1 and 2 Meg. in size, and they are not too knowledgeable about computers. I want to disable the form buttons so they can't hit them after they hit the "upload" button. We're trying to prevent them from...
1
6227
by: Edwin Knoppert | last post by:
I post this again, no answer before. During the beta version it worked, the same code does no longer work in the new release. I have a simple gridview with ButtonField, the button deletes a records. So i want to add a confirm in javascript. How will i set the javascript function (OnClientClick) for this ButtonField?
3
13607
by: anadimpa | last post by:
Hello all I build a javascript function string in the code behind and register it in the Page_Load of my User Control. I do this because I build the javascript based on some variables that are passed to this user control. How do I (or from where do I) call this function? I tried several ways like: this.Attributes.Add("onLoad", "javascript:openDoc();"); in the page_load / page_prerender etc...
2
4219
by: Ben | last post by:
Hi, When a user wants to start the application, aspnet checks a boolean value in a field of the database. If that value is 'false', then i want to execute a ALERT in javascript telling the applicatin is closed. This is a part of the .aspx.vb file: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ....
0
8996
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9562
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.