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. Advertising

  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. Advertising

  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. 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. =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?=

    Help on seting project path

    =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?=, Sep 6, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    419
    S. Justin Gengo
    Sep 6, 2005
  2. Rob R. Ainscough

    IIS and seting .aspx page as default?

    Rob R. Ainscough, May 19, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    682
    Rob R. Ainscough
    May 22, 2006
  3. bryan
    Replies:
    7
    Views:
    406
    Eric Sosman
    May 10, 2004
  4. mc
    Replies:
    5
    Views:
    5,033
    MehulMistry
    Mar 16, 2007
  5. dmaziuk
    Replies:
    3
    Views:
    625
    Chris Gonnerman
    Jan 25, 2011
Loading...

Share This Page