开发者

Add client-side events to ASP.Net custom control at runtime

开发者 https://www.devze.com 2022-12-25 16:08 出处:网络
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 gene

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.My开发者_如何学JAVAControl, {}, 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?


Check This

Sys.Application.add_load(handler);


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号