Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I created event receiver that uses web service, and I want to show the result on popup window.

I know we can use different kinds of redirect in synchronous receivers, but it is called by checkbox in filtered datasheet view, so I'm not able to make redirect back to my page.

So I need to show some popup window. I know we can get HttpContext object in constructor of event receiver, but now I don't know how to call javascript window?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Event Receivers are not UI related. You cannot open popups from them.
Also do not be sure of getting HttpContext in event receiver code.
Events can be fired by many agents other than user action in browser, e.g. if event is fired as a result of an action by by timer job or console application or workflow, HttpContext will be null so it is absolutely not good design to have redirection logic in event receiver.

share|improve this answer
    
justforkix09, thank You for Your answer! Yes I know that work with HttpContext from event receiver is a bad hack, but in my case I understand the risks and in my case is more important to show this message :( –  Rockie Feb 27 '12 at 14:40
    
I tried out your scenario, used Response.Write to add javascript to the page. It executes fine on list view but does not work on datasheet view. Asynchronous functionality of the data sheet object doesn't let the additional script tag come on to the page –  justforkix09 Feb 28 '12 at 7:50
    
justforkix09Gm, thank You for answer! Can You show Your code-snippet? I tried this(kink below) to show the window and it does nothing(no exceptions but no work too), in datasheet and form views no matter madskristensen.net/post/… –  Rockie Feb 28 '12 at 12:31
    
That's my variant: [code] public HttpContext context; public Page page; public MyReceiver() { context = HttpContext.Current; page = context.CurrentHandler as Page; } // and then I tried to show like this: Alert.Show(page, "A"); [/code] –  Rockie Feb 28 '12 at 12:38
    
I checked that link and my guess is [HttpContext.Current.CurrentHandler as Page] will be null as event is not being handled by page handler. As there is a null check ahead, you are not getting any exception. As for my code, I did not bother with registering the script , just wrote [Context.Response.Write("<script type='text/javascript'>alert('This message is from event handler');</script>");] and this worked for normal list/forms view.(Context is the HttpContext object stored by the constructor) –  justforkix09 Feb 28 '12 at 19:20
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.