views:

2982

answers:

3

In an ASP.NET page I have a user control and I want to perform some action within it using javascript. When that action is complete I want to raise an event (again in javascript) to be picked up by the containing ASP.NET page (again in javascript).

The reason I want to do this is because I have more than one user control on the page and I need the action performed in one user control to instantiate an action in another user control without doing a postback.

Does anyone know how to do this?

Many thanks.

A: 
Ady
A: 

Hi and thanks for the response. What I'm trying to do is create some form of encapsulation. So if the javascript code does something in one user control that user control shouldn't know of the impact else where. It would raise an event in javascript which can be picked up by asp.net page rendered javascript which can in turn call a javascript method in another user control if it needs to. The idea here is also to eliminate any need for a postback.

Hope this expains it better.

Peanut
You should probably modify your original question to be more clear, rather than posting an answer to the question as a replay to an answer. It gets a bit confusing otherwise.
Ady
+2  A: 

I think the simple way to implement what you are describing, is to forget about javacript events, and just supply a "callback" function to the user-controls.

The way i would implement it, would be to expose a public property on the user control, which takes the name of this javascript "callback-function". The user-control is then responsible for calling this function after it has finished its client-side job.

So the page that uses the user-controls will have to implement this javascript "callback-function", and then supply the name in properties to the user controls.

Makes sense?

Tom Jelen
That looks good - think that could be what I'm after - will do some research into it. Thanks.
Peanut