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

G

Geoff Davis

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

Geoff Davis

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());
}
 
J

Jiho Han

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

Geoff Davis

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top