views:

802

answers:

1

Is it possible to raise a "custom event" in an ASP.NET user control and to subscribe to the event in the calling page? This way I can have any containing page react to changes in a user control without having to do a partial or full postback.

+2  A: 

You're trying to mix server-side code with client-side code. You're probably better off using the built-in javascript events:

control.Attributes.Add("onclick", "mgr.Click();"); //server-side

//Javascript:
var mgr = new Object();
mgr.Click = new function(e) { //...

That said, with sufficient effort and a lot of hackery, you could probably get it to render out enough javascript and use AJAX calls to possibly acheive the effect; but it probably wouldn't be worth it; and isn't built-in.

Or - if your aim is to raise custom events server-side (rather than client-side) and handle them in javascript, render out calls to the functions:

this.Controls.Add(new LiteralControl("<script type=\"text/javascript\">mgr.Filter('people');</script>"));
Tom Ritter