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?