0

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?

2 Answers 2

2

Check This

Sys.Application.add_load(handler);
Sign up to request clarification or add additional context in comments.

Comments

0

Actually, they would be able to add the event handler using any of the javascript library's like jQuery using:

$(document).ready(function(){

 $('#<%= my_control_id.ClientId%>').click(function(e){
  // do something...
 });

});

HTH.

1 Comment

This is a complex little custom control, and the event to be handled does not correspond to an event on any particular DOM element. The handler must be applied to the object created in the IScriptControl-generated code. Unfortunately the object after any other script blocks have executed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.