onLoad Javascript

Discussion in 'ASP .Net' started by chrispragash@hotmail.com, Aug 29, 2005.

  1. Guest

    Hello all,

    I am trying to hide a panel when my asp.net page first renders - the
    objective is to toggle the visibility at the click of a button. I wrote
    a javascript (with script like ClientID.style.visibility = "hidden"),
    registered this script using Page.RegisterClientScriptBlock, and added
    an Attribute to the control (Control.Attributes.Add("onLoad", "Id of
    script")). The javascript is not being called at all!. Any ideas would
    be of great help.

    Regards,
    Chris
    , Aug 29, 2005
    #1
    1. Advertising

  2. Hans Kesting Guest

    wrote:
    > Hello all,
    >
    > I am trying to hide a panel when my asp.net page first renders - the
    > objective is to toggle the visibility at the click of a button. I
    > wrote a javascript (with script like ClientID.style.visibility =
    > "hidden"), registered this script using
    > Page.RegisterClientScriptBlock, and added an Attribute to the control
    > (Control.Attributes.Add("onLoad", "Id of script")). The javascript is
    > not being called at all!. Any ideas would be of great help.
    >
    > Regards,
    > Chris


    When you say "id of script", do you mean just the name of the function,
    or even the code that you used registering the script block?
    You should use the name of the function, followed by ( ) (that is, a plain function call).
    The registration name has no meaning at all, client-side.

    You could also use Page.RegisterStartupScript. This code will execute when most of
    the page has already been loaded.

    What does the generated code look like in the browser (do a "view source"
    and search for your code)? You need to include the <script> tags
    in the code-block.

    Hans Kesting
    Hans Kesting, Aug 29, 2005
    #2
    1. Advertising

  3. Guest

    Hans,

    Thanks for responding. In the attributes, I am actually specifying the
    name of the javascript function, I verfied this by executing the
    function in onClick and everything works fine. The problem is I want to
    execute this when the page loads. And all this code is in a Server
    control. Any ideas or suggestions?

    Thanks,
    Chris
    , Aug 29, 2005
    #3
  4. Hans Kesting Guest

    wrote:
    > Hans,
    >
    > Thanks for responding. In the attributes, I am actually specifying the
    > name of the javascript function, I verfied this by executing the
    > function in onClick and everything works fine. The problem is I want
    > to execute this when the page loads. And all this code is in a Server
    > control. Any ideas or suggestions?
    >
    > Thanks,
    > Chris


    Executing code in the onLoad of a *page* will work. Be sure to add a ";" after
    your call, .Net may append code of it's own.
    A *control* is not something that is recognised as a separate entity at the client,
    so I don't think it's possible to add an onLoad handler to a *control*.

    Hans Kesting
    Hans Kesting, Aug 29, 2005
    #4
  5. Bruce Barker Guest

    only the <body> tag has an onload event in the browser.

    <body onload="myclientscript()">

    you could put a runat server and id tag and do the add attribute. as you
    just want to change the style, use the RegisterStartupScript (which renders
    just before the </form> tag).

    -- bruce (sqlwork.com)


    <> wrote in message
    news:...
    > Hello all,
    >
    > I am trying to hide a panel when my asp.net page first renders - the
    > objective is to toggle the visibility at the click of a button. I wrote
    > a javascript (with script like ClientID.style.visibility = "hidden"),
    > registered this script using Page.RegisterClientScriptBlock, and added
    > an Attribute to the control (Control.Attributes.Add("onLoad", "Id of
    > script")). The javascript is not being called at all!. Any ideas would
    > be of great help.
    >
    > Regards,
    > Chris
    >
    Bruce Barker, Aug 29, 2005
    #5
  6. babie984

    Joined:
    Aug 2, 2009
    Messages:
    1
    scripting...

    hi.... am having a problem with javascripting. have this datepicker, want to show in the page that when the date picked is changed, the date in the textbox and the date picked in the end date will automatically changed into the selected start date. already can do this but the thing is still have to press enter. want it in a way that it will just automatically change. how can i do this? is there any chance that i can do this?
    babie984, Aug 2, 2009
    #6
    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. John E
    Replies:
    0
    Views:
    2,026
    John E
    Jul 31, 2003
  2. Fabio R.
    Replies:
    0
    Views:
    795
    Fabio R.
    Mar 25, 2005
  3. David Otton

    window.onload and body.onload differences

    David Otton, Nov 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    549
    Martin Honnen
    Nov 4, 2004
  4. Replies:
    5
    Views:
    258
    Thomas 'PointedEars' Lahn
    May 15, 2005
  5. marco

    onload -->* no onload

    marco, Jun 22, 2006, in forum: Javascript
    Replies:
    7
    Views:
    202
    marco
    Jun 24, 2006
Loading...

Share This Page