Raising javascript events in an ASP.NET custom control
1 answer
You are trying to mix server side code with client side code. You are probably better off using javascript inline events:
control.Attributes.Add("onclick", "mgr.Click();"); //server-side
//Javascript:
var mgr = new Object();
mgr.Click = new function(e) { //...
However, with enough effort and a lot of hacking, you could probably get it to render enough javascript and use AJAX calls to possibly get the effect; but it probably wouldn't be worth it; and is not built in.
Or - if your goal is to raise custom events on the server side (not client side) and handle them in javascript, output the function calls:
this.Controls.Add(new LiteralControl("<script type=\"text/javascript\">mgr.Filter('people');</script>"));
+2
source to share