<body onload="alert('Hello');"> does not work! Why?

Discussion in 'ASP .Net' started by =?Utf-8?B?Q2FsdmluIEtE?=, Aug 25, 2005.

  1. Hi everyone,
    Has someone out there experienced the same problem? What i wanted to do is
    to display a popup window (modal) upon the loading of a webpage. Here is my
    code sample (in html view):
    <HTML>
    <HEAD>
    ....
    </HEAD>
    <BODY onload="ShowPopUp();" MS_POSITIONING="GridLayout">
    ....
    ....
    </BODY>
    </HTML>
    Where ShowPopUp() is a JavaScript function to display the popup window.
    However it does not get called. When I replaced the function with just a
    simple alert('Hello') function, still nothing is displayed at load up.
    However, crazy enough, I got it to work on some of the pages though.?????
    Is there anything that is missing or shouldn't be there?
    Please help me...
    Calvin
    =?Utf-8?B?Q2FsdmluIEtE?=, Aug 25, 2005
    #1
    1. Advertising

  2. Try using :-RegisterStartupScript Method

    Check sample at:-
    http://www.codeproject.com/aspnet/Mayank_Gupta.asp
    or
    http://www.aspnetpro.com/NewsletterArticle/2004/10/asp200410bm_l/asp200410bm_l.asp

    http://msdn.microsoft.com/library/d...mWebUIPageClassRegisterStartupScriptTopic.asp
    Hope that helps
    Patrick

    "Calvin KD" <> wrote in message
    news:...
    > Hi everyone,
    > Has someone out there experienced the same problem? What i wanted to do is
    > to display a popup window (modal) upon the loading of a webpage. Here is

    my
    > code sample (in html view):
    > <HTML>
    > <HEAD>
    > ...
    > </HEAD>
    > <BODY onload="ShowPopUp();" MS_POSITIONING="GridLayout">
    > ...
    > ...
    > </BODY>
    > </HTML>
    > Where ShowPopUp() is a JavaScript function to display the popup window.
    > However it does not get called. When I replaced the function with just a
    > simple alert('Hello') function, still nothing is displayed at load up.
    > However, crazy enough, I got it to work on some of the pages though.?????
    > Is there anything that is missing or shouldn't be there?
    > Please help me...
    > Calvin
    Patrick.O.Ige, Aug 25, 2005
    #2
    1. Advertising

  3. It looks ok. Do you have javascript enabled on that machine?

    Eliyahu

    "Calvin KD" <> wrote in message
    news:...
    > Hi everyone,
    > Has someone out there experienced the same problem? What i wanted to do is
    > to display a popup window (modal) upon the loading of a webpage. Here is

    my
    > code sample (in html view):
    > <HTML>
    > <HEAD>
    > ...
    > </HEAD>
    > <BODY onload="ShowPopUp();" MS_POSITIONING="GridLayout">
    > ...
    > ...
    > </BODY>
    > </HTML>
    > Where ShowPopUp() is a JavaScript function to display the popup window.
    > However it does not get called. When I replaced the function with just a
    > simple alert('Hello') function, still nothing is displayed at load up.
    > However, crazy enough, I got it to work on some of the pages though.?????
    > Is there anything that is missing or shouldn't be there?
    > Please help me...
    > Calvin
    Eliyahu Goldin, Aug 25, 2005
    #3
  4. Where have you defined the JavaScript function? When you use the body
    "onload" event to call a function, it must be declared in the head. The
    RegisterStartupScript() method puts the JavaScript code that should run when
    the page is loaded at the bottom of the form. This always works, as long as
    there are no references in the script to HTML elements below the script in
    the page. This is due to the fact that browsers don't always get all of the
    HTML for the page in one swell foop.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Paranoia is just a state of mind.

    "Calvin KD" <> wrote in message
    news:...
    > Hi everyone,
    > Has someone out there experienced the same problem? What i wanted to do is
    > to display a popup window (modal) upon the loading of a webpage. Here is
    > my
    > code sample (in html view):
    > <HTML>
    > <HEAD>
    > ...
    > </HEAD>
    > <BODY onload="ShowPopUp();" MS_POSITIONING="GridLayout">
    > ...
    > ...
    > </BODY>
    > </HTML>
    > Where ShowPopUp() is a JavaScript function to display the popup window.
    > However it does not get called. When I replaced the function with just a
    > simple alert('Hello') function, still nothing is displayed at load up.
    > However, crazy enough, I got it to work on some of the pages though.?????
    > Is there anything that is missing or shouldn't be there?
    > Please help me...
    > Calvin
    Kevin Spencer, Aug 25, 2005
    #4
  5. Thank you so much for all your responses.
    My ShowPopUp() javascript function is declared in the header on the same
    page as where it's called. What really puzzled me was even the
    onload="alert('Hello');" did not display the message at load up.
    What I really want to do is showing the popup (modal) window, which is a
    Search screen where the user selects a record. When the popup is closed, the
    selected ID is returned back to the parent window, put the returned ID in a
    hidden field then reload the page so that the rest of the details can be
    displayed on the screen.
    How easy is it to do this using the RegisterStartupScript facility?

    Thanks again,
    Calvin

    "Calvin KD" wrote:

    > Hi everyone,
    > Has someone out there experienced the same problem? What i wanted to do is
    > to display a popup window (modal) upon the loading of a webpage. Here is my
    > code sample (in html view):
    > <HTML>
    > <HEAD>
    > ...
    > </HEAD>
    > <BODY onload="ShowPopUp();" MS_POSITIONING="GridLayout">
    > ...
    > ...
    > </BODY>
    > </HTML>
    > Where ShowPopUp() is a JavaScript function to display the popup window.
    > However it does not get called. When I replaced the function with just a
    > simple alert('Hello') function, still nothing is displayed at load up.
    > However, crazy enough, I got it to work on some of the pages though.?????
    > Is there anything that is missing or shouldn't be there?
    > Please help me...
    > Calvin
    =?Utf-8?B?Q2FsdmluIEtE?=, Aug 26, 2005
    #5
  6. Calvin.
    I posted some sample links in my earlier post how you could use it.
    If u still can't figure it out post your Js and will feed you back.
    Patrick


    "Calvin KD" <> wrote in message
    news:...
    > Thank you so much for all your responses.
    > My ShowPopUp() javascript function is declared in the header on the same
    > page as where it's called. What really puzzled me was even the
    > onload="alert('Hello');" did not display the message at load up.
    > What I really want to do is showing the popup (modal) window, which is a
    > Search screen where the user selects a record. When the popup is closed,

    the
    > selected ID is returned back to the parent window, put the returned ID in

    a
    > hidden field then reload the page so that the rest of the details can be
    > displayed on the screen.
    > How easy is it to do this using the RegisterStartupScript facility?
    >
    > Thanks again,
    > Calvin
    >
    > "Calvin KD" wrote:
    >
    > > Hi everyone,
    > > Has someone out there experienced the same problem? What i wanted to do

    is
    > > to display a popup window (modal) upon the loading of a webpage. Here is

    my
    > > code sample (in html view):
    > > <HTML>
    > > <HEAD>
    > > ...
    > > </HEAD>
    > > <BODY onload="ShowPopUp();" MS_POSITIONING="GridLayout">
    > > ...
    > > ...
    > > </BODY>
    > > </HTML>
    > > Where ShowPopUp() is a JavaScript function to display the popup window.
    > > However it does not get called. When I replaced the function with just a
    > > simple alert('Hello') function, still nothing is displayed at load up.
    > > However, crazy enough, I got it to work on some of the pages

    though.?????
    > > Is there anything that is missing or shouldn't be there?
    > > Please help me...
    > > Calvin
    Patrick.O.Ige, Aug 26, 2005
    #6
  7. Thanks so much Patrick. I think I have some ideas as how to do it and I will
    give it a shot.
    Would you be kind enough to check out this post again next week in case I
    still have issues and may ask for your help?
    Thanks again,
    Calvin.

    "Patrick.O.Ige" wrote:

    > Calvin.
    > I posted some sample links in my earlier post how you could use it.
    > If u still can't figure it out post your Js and will feed you back.
    > Patrick
    >
    >
    > "Calvin KD" <> wrote in message
    > news:...
    > > Thank you so much for all your responses.
    > > My ShowPopUp() javascript function is declared in the header on the same
    > > page as where it's called. What really puzzled me was even the
    > > onload="alert('Hello');" did not display the message at load up.
    > > What I really want to do is showing the popup (modal) window, which is a
    > > Search screen where the user selects a record. When the popup is closed,

    > the
    > > selected ID is returned back to the parent window, put the returned ID in

    > a
    > > hidden field then reload the page so that the rest of the details can be
    > > displayed on the screen.
    > > How easy is it to do this using the RegisterStartupScript facility?
    > >
    > > Thanks again,
    > > Calvin
    > >
    > > "Calvin KD" wrote:
    > >
    > > > Hi everyone,
    > > > Has someone out there experienced the same problem? What i wanted to do

    > is
    > > > to display a popup window (modal) upon the loading of a webpage. Here is

    > my
    > > > code sample (in html view):
    > > > <HTML>
    > > > <HEAD>
    > > > ...
    > > > </HEAD>
    > > > <BODY onload="ShowPopUp();" MS_POSITIONING="GridLayout">
    > > > ...
    > > > ...
    > > > </BODY>
    > > > </HTML>
    > > > Where ShowPopUp() is a JavaScript function to display the popup window.
    > > > However it does not get called. When I replaced the function with just a
    > > > simple alert('Hello') function, still nothing is displayed at load up.
    > > > However, crazy enough, I got it to work on some of the pages

    > though.?????
    > > > Is there anything that is missing or shouldn't be there?
    > > > Please help me...
    > > > Calvin

    >
    >
    >
    =?Utf-8?B?Q2FsdmluIEtE?=, Aug 26, 2005
    #7
  8. Thanks so much Patrick. I have managed to get it to work base on your ideas.
    So thanks again.
    Cheers.
    Calvin

    "Patrick.O.Ige" wrote:

    > Calvin.
    > I posted some sample links in my earlier post how you could use it.
    > If u still can't figure it out post your Js and will feed you back.
    > Patrick
    >
    >
    > "Calvin KD" <> wrote in message
    > news:...
    > > Thank you so much for all your responses.
    > > My ShowPopUp() javascript function is declared in the header on the same
    > > page as where it's called. What really puzzled me was even the
    > > onload="alert('Hello');" did not display the message at load up.
    > > What I really want to do is showing the popup (modal) window, which is a
    > > Search screen where the user selects a record. When the popup is closed,

    > the
    > > selected ID is returned back to the parent window, put the returned ID in

    > a
    > > hidden field then reload the page so that the rest of the details can be
    > > displayed on the screen.
    > > How easy is it to do this using the RegisterStartupScript facility?
    > >
    > > Thanks again,
    > > Calvin
    > >
    > > "Calvin KD" wrote:
    > >
    > > > Hi everyone,
    > > > Has someone out there experienced the same problem? What i wanted to do

    > is
    > > > to display a popup window (modal) upon the loading of a webpage. Here is

    > my
    > > > code sample (in html view):
    > > > <HTML>
    > > > <HEAD>
    > > > ...
    > > > </HEAD>
    > > > <BODY onload="ShowPopUp();" MS_POSITIONING="GridLayout">
    > > > ...
    > > > ...
    > > > </BODY>
    > > > </HTML>
    > > > Where ShowPopUp() is a JavaScript function to display the popup window.
    > > > However it does not get called. When I replaced the function with just a
    > > > simple alert('Hello') function, still nothing is displayed at load up.
    > > > However, crazy enough, I got it to work on some of the pages

    > though.?????
    > > > Is there anything that is missing or shouldn't be there?
    > > > Please help me...
    > > > Calvin

    >
    >
    >
    =?Utf-8?B?Q2FsdmluIEtE?=, Aug 29, 2005
    #8
    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. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,765
    Smokey Grindel
    Dec 2, 2006
  2. David Otton

    window.onload and body.onload differences

    David Otton, Nov 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    535
    Martin Honnen
    Nov 4, 2004
  3. Replies:
    5
    Views:
    251
    Thomas 'PointedEars' Lahn
    May 15, 2005
  4. Replies:
    0
    Views:
    169
  5. Replies:
    11
    Views:
    285
    Thomas 'PointedEars' Lahn
    Dec 11, 2006
Loading...

Share This Page