Add client-side events to ASP.Net custom control at runtime
Posted
by nw
on Stack Overflow
See other posts from Stack Overflow
or by nw
Published on 2010-04-06T18:09:39Z
Indexed on
2010/04/06
18:13 UTC
Read the original article
Hit count: 311
I'm building an ASP.net custom control that implements IScriptControl
. I would like other users of my control to be able to assign client-side event handlers to the control. Unfortunately the JS generated by IScriptControl
is always injected at the very bottom of the rendered page (see below), so any attempt to assign an event handler in the ASPX page fails because the code executes too early.
...
<script type="text/javascript">
//<![CDATA[
Sys.Application.initialize();
Sys.Application.add_init(function() {
$create(MyNamespace.MyControl, {}, null, null, $get("my_control_id"));
});
//]]>
</script>
</form>
What's the right way to assign an event handler to the instantiated control upon page load?
© Stack Overflow or respective owner