CustomControl and body.onload

Discussion in 'ASP .Net Web Controls' started by Ernest Morariu, Mar 22, 2006.

  1. Hi All !

    I subclassed a Label control(ASP2.0) .
    How to modify(form inside my control) the attribute onload of the <body> of
    the page where my control resides?

    I need the browser to execute a javascript function(when the page loads)
    that my control registers with ClientScriptManager.

    Ernest
    Ernest Morariu, Mar 22, 2006
    #1
    1. Advertising

  2. Ernest Morariu

    Guest

    Here's a method that I would personally NOT used butmight suit your
    needs.

    1) Make the page body tag of a server control.
    i.e.
    <body id="body1" runat="server">
    ....
    </body>
    2) Use FindControl() to find the body within the subclass and inject
    your javascript.
    The subclassed OnLoad handler might be a good location to do this.
    i.e
    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
    MyBase.OnLoad(e)
    Dim body As HTMLGenericControl =
    Me.Page.FindControl("body")
    body.Attributes.Add("OnLoad",
    "javascript:document.bgcolor='red'")
    End Sub
    , Mar 22, 2006
    #2
    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. Fabio R.
    Replies:
    0
    Views:
    792
    Fabio R.
    Mar 25, 2005
  2. Andy Fish
    Replies:
    0
    Views:
    335
    Andy Fish
    Apr 12, 2006
  3. David Otton

    window.onload and body.onload differences

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

    onload -->* no onload

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

Share This Page