Sunday, March 11, 2012

ModalPopup and Javascript question

That's a pretty big ask!

One option you can consider is to do an ajax postback instead of trying to do it all via JS and web services. That way you are able to programmatically show the modalpopup if necessary and do any serverside processing, e.g. delete tasks, rebind grids, etc. There's no doubt that you could do it all via JS but it is going to be a lot trickier and I'm not sure that you are going to gain that much (unless the amount of data sent over the wire is a major concern for you).


If you look in the help docs for the ajax lib they have some nice examples there.

Basically you should set up a web service with two web methods, one for checking if exists, and one for deleting. Then add reference to this service in your script manager.
Call the first method, ask for confirmation, if yes then call the second one. Or something like that.

This is really easy when you use the ajax library. Here's a little code sample.

function CheckIfTaskPresent(taskId){ NameSpace.YourWebService.YourWebMethod( taskId, OnSucceeded, OnFailed);}
function DeleteTask(taskId){ NameSpace.YourWebService.YourWebMethodThatDeletes( taskId, OnSucceeded, OnFailed);}// Callback function invoked on successful // completion of the page method.function OnSucceeded(result, userContext, methodName) {if (methodName =="CheckIfTaskPresent") {// result is the return value from the web serviceif (Confirm("Do you really want to delete it?") DeleteTask(result);// Calls the web method that deletes }
else if (methodName == "DeleteTask")
{
// notify the user that the task was deleted

}}// Callback function invoked on failure // of the page method.function OnFailed(error, userContext, methodName) {if(error !==null) { alert("An exception was thrown from the web method: " + error.get_message()); }}

I recently did something similar and I really enjoyed how easy it was using the ajax library.

No comments:

Post a Comment