Executing Javascript on Page Load

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan Wood

    Executing Javascript on Page Load

    I've created some javascript and added it to my page (from a user control)
    using Page.ClientScri pt.RegisterClie ntScriptBlock. The javascript hides and
    shows certain elements in response to radio buttons being selected.

    It seems to work fine except that I really need to run the script when the
    page loads so the required elements are shown or hidden (some of these
    elements do not have runat="server") .

    So, I use the following code:

    Page.Form.Attri butes.Add("onlo ad", initFunction);

    Where initFunction is something like "OnUserFood ()".

    This seems to have no effect. And looking at the resulting HTML, I notice
    that my script appears within the form instead of in the header. I'm not
    sure if this matters. But, although the onload attribute correctly appears
    in the form tag, again, it doesn't appear to be actually making the call.

    Any suggestions?

    Thanks.

    --
    Jonathan Wood
    SoftCircuits Programming


  • Scott Roberts

    #2
    Re: Executing Javascript on Page Load


    "Jonathan Wood" <jwood@softcirc uits.comwrote in message
    news:OCWPv3sbIH A.1168@TK2MSFTN GP02.phx.gbl...
    I've created some javascript and added it to my page (from a user control)
    using Page.ClientScri pt.RegisterClie ntScriptBlock. The javascript hides
    and shows certain elements in response to radio buttons being selected.
    >
    It seems to work fine except that I really need to run the script when the
    page loads so the required elements are shown or hidden (some of these
    elements do not have runat="server") .
    >
    So, I use the following code:
    >
    Page.Form.Attri butes.Add("onlo ad", initFunction);
    >
    Where initFunction is something like "OnUserFood ()".
    >
    This seems to have no effect. And looking at the resulting HTML, I notice
    that my script appears within the form instead of in the header. I'm not
    sure if this matters. But, although the onload attribute correctly appears
    in the form tag, again, it doesn't appear to be actually making the call.
    >
    Any suggestions?
    Page.ClientScri pt.RegisterClie ntStartupScript

    Comment

    • Jonathan Wood

      #3
      Re: Executing Javascript on Page Load

      Err... That would make sense, wouldn't it?

      Haven't used that before but will investigate further.

      Thanks!

      --
      Jonathan Wood
      SoftCircuits Programming


      "Scott Roberts" <sroberts@no.sp am.here-webworks-software.comwro te in
      message news:OTtf9otbIH A.5400@TK2MSFTN GP03.phx.gbl...
      >
      "Jonathan Wood" <jwood@softcirc uits.comwrote in message
      news:OCWPv3sbIH A.1168@TK2MSFTN GP02.phx.gbl...
      >I've created some javascript and added it to my page (from a user
      >control) using Page.ClientScri pt.RegisterClie ntScriptBlock. The
      >javascript hides and shows certain elements in response to radio buttons
      >being selected.
      >>
      >It seems to work fine except that I really need to run the script when
      >the page loads so the required elements are shown or hidden (some of
      >these elements do not have runat="server") .
      >>
      >So, I use the following code:
      >>
      >Page.Form.Attr ibutes.Add("onl oad", initFunction);
      >>
      >Where initFunction is something like "OnUserFood ()".
      >>
      >This seems to have no effect. And looking at the resulting HTML, I notice
      >that my script appears within the form instead of in the header. I'm not
      >sure if this matters. But, although the onload attribute correctly
      >appears in the form tag, again, it doesn't appear to be actually making
      >the call.
      >>
      >Any suggestions?
      >
      Page.ClientScri pt.RegisterClie ntStartupScript
      >

      Comment

      Working...