Controls with a client side onLoad function or seting a cursor server side

Discussion in 'ASP .Net Building Controls' started by Geoff Davis, Jan 13, 2004.

  1. Geoff Davis

    Geoff Davis Guest

    Is there any way to create a web control that calls a client side
    onLoad function?

    Its diffucilt since you are not able to access the form or body tags
    in the control.

    I inherit from:
    System.Web.UI.WebControls.WebControl

    What I'm really trying to do is set a cursor, i haven't been able to
    set it server side only in JavaScript.

    Any help would be great.
     
    Geoff Davis, Jan 13, 2004
    #1
    1. Advertisements

  2. Geoff Davis

    Geoff Davis Guest

    I worked it out.

    By overiding Render, calling base.Render(output) and then adding to
    the HTML output stream i can run a script after the control had been
    rendered. Previously i could only run a script before it was rendered
    and that meant the control didn't exist yet.

    //In custom control (which is a composite control)
    protected override void Render(HtmlTextWriter output)
    {
    //add HTML components to the output stream
    base.Render(output);

    StringWriter s = new StringWriter();s.WriteLine(@"
    <script language='JavaScript'>
    document.getElementById('MyControl').style.cursor = 'newCursor.cur';
    </script>");
    output.WriteLine(s.ToString());
    }

    (Geoff Davis) wrote in message news:<>...
    > Is there any way to create a web control that calls a client side
    > onLoad function?
    >
    > Its diffucilt since you are not able to access the form or body tags
    > in the control.
    >
    > I inherit from:
    > System.Web.UI.WebControls.WebControl
    >
    > What I'm really trying to do is set a cursor, i haven't been able to
    > set it server side only in JavaScript.
    >
    > Any help would be great.
     
    Geoff Davis, Jan 13, 2004
    #2
    1. Advertisements

  3. Geoff Davis

    Jiho Han Guest

    Although that approach is valid, the recommended approach is to use
    Page.RegisterStartUpScript method.
    Look it up in the SDK doc.

    "Geoff Davis" <> wrote in message
    news:...
    > I worked it out.
    >
    > By overiding Render, calling base.Render(output) and then adding to
    > the HTML output stream i can run a script after the control had been
    > rendered. Previously i could only run a script before it was rendered
    > and that meant the control didn't exist yet.
    >
    > //In custom control (which is a composite control)
    > protected override void Render(HtmlTextWriter output)
    > {
    > //add HTML components to the output stream
    > base.Render(output);
    >
    > StringWriter s = new StringWriter();s.WriteLine(@"
    > <script language='JavaScript'>
    > document.getElementById('MyControl').style.cursor = 'newCursor.cur';
    > </script>");
    > output.WriteLine(s.ToString());
    > }
    >
    > (Geoff Davis) wrote in message

    news:<>...
    > > Is there any way to create a web control that calls a client side
    > > onLoad function?
    > >
    > > Its diffucilt since you are not able to access the form or body tags
    > > in the control.
    > >
    > > I inherit from:
    > > System.Web.UI.WebControls.WebControl
    > >
    > > What I'm really trying to do is set a cursor, i haven't been able to
    > > set it server side only in JavaScript.
    > >
    > > Any help would be great.
     
    Jiho Han, Jan 14, 2004
    #3
  4. Geoff Davis

    Geoff Davis Guest

    Thanks, I gave it a go,

    I wasn't sure if you could register more than one start up script.

    I didn't want to make it so I remove the ability for someone using my
    control to be able to register a start up script.

    but you can register many if you want to.

    thanks.



    "Jiho Han" <> wrote in message news:<>...
    > Although that approach is valid, the recommended approach is to use
    > Page.RegisterStartUpScript method.
    > Look it up in the SDK doc.
     
    Geoff Davis, Jan 15, 2004
    #4
    1. Advertisements

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. ken busse
    Replies:
    2
    Views:
    552
  2. Matt
    Replies:
    14
    Views:
    4,546
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  3. Mong
    Replies:
    5
    Views:
    4,971
    Kevin Spencer
    May 7, 2004
  4. msnews
    Replies:
    0
    Views:
    570
    msnews
    May 27, 2005
  5. Jake
    Replies:
    2
    Views:
    534
    Steve C. Orr [MVP, MCSD]
    Aug 17, 2005
  6. dmaziuk
    Replies:
    3
    Views:
    979
    Chris Gonnerman
    Jan 25, 2011
  7. Zoe Hart
    Replies:
    1
    Views:
    602
    Scott Wisniewski
    Jan 8, 2004
  8. Cathryn Lindner

    client side script with server side controls

    Cathryn Lindner, Oct 24, 2003, in forum: Javascript
    Replies:
    1
    Views:
    238
    Thomas 'PointedEars' Lahn
    Nov 23, 2003
Loading...