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.

1 Answer 1

2

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>"));
Sign up to request clarification or add additional context in comments.

1 Comment

isn't that ASP.NET's M.O.? mixing client-side and server-side?

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.