This topic is locked
[SOLVED]

 ClientSide Confirmation before ServerSide process

10/13/2017 12:00:46 PM
ASPRunner.NET General questions
M
Molasar author

Hello,
Suppose I want a page-level button (not grid-level), which executes a stored procedure.
Now this stored procedure executes an End-of-Day process, so I must ask for confirmation beforehand.
When I add a button, I get 3 events: Client Before, Server and Client After.
How can I ask the user for confirmation on the Client Before event, before the Server event fires?
If some of this code (Server side, etc) needs to be taken out of the button Server event, it's fine with me.
Any pointers?
This is my current code, which does not work. It uses as nice jquery dialog (maybe not the best approach, but quite nice looking):



function OnBefore(params,ctrl,row)

{

$("#wsdialog").dialog({

autoOpen: false,

modal: true,

'buttons': {

'Aceptar': function(){

params["EOD"] = "Go";

$('#wsdialog').dialog('close');



},

'Cancelar': function(){

params["EOD"] = "Abort";

$('#wsdialog').dialog('close');

location.reload();

}

}

});
$("#wsdialog").dialog("option", "width", 275);

$("#wsdialog").dialog("option", "height", 175);

$("#wsdialog").dialog("option", "resizable", false);

$("#wsdialog").css("background-color", "linear-gradient(0.5turn, rgb(0, 204, 224), rgb(0, 255, 255)) 0px 0px rgba(0, 0, 0, 0);");

$("#wsdialogimg").children('img').attr('src','/images/question-icon.png');

$("#wsdialogtxt1").text("Se va a iniciar el Cierre del Día.");

$("#wsdialogtxt2").text("¿Está seguro que desea continuar?");

$("#wsdialog").dialog("open");

}




public XVar OnServer(dynamic parameters, dynamic result)

{

if (parameters["EOD"].ToString() == "Go")

{

string sql = "DECLARE @returnstatus int EXEC @returnstatus = sp_StartEOD select @returnstatus";

XVar returnstatus = tDAL.DBLookup(sql);

result["exitcode"] = returnstatus.ToString();

}

}




function OnAfter(result,ctrl)

{

var message = params["EOD"];

ctrl.setMessage(message);

alert(params["EOD"]);
if (params["EOD"]=="Go") {

if (result["exitcode"] ==1) {

$('#wsdialog').dialog('close');
$("#wsdialog").dialog({

autoOpen: false,

modal: true,

'buttons': {

'Aceptar': function(){

// here is the modification of the button

// opacity set to 25%, all events unbound

location.reload();

}

}

});

$("#wsdialog").dialog("option", "width", 275);

$("#wsdialog").dialog("option", "height", 175);

$("#wsdialog").dialog("option", "resizable", false);

$("#wsdialog").css("background-color", "orange");

$("#wsdialogimg").children('img').attr('src','/images/alert-icon.png');

$("#wsdialogtxt1").text("Error en Cierre de Día.");

$("#wsdialogtxt2").text("Favor de reintentar más tarde.");

$("#wsdialog").dialog("open");

}

else if (result["exitcode"] ==2) {

$('#wsdialog').dialog('close');
$("#wsdialog").dialog({

autoOpen: false,

modal: true,

'buttons': {

'Aceptar': function(){

// here is the modification of the button

// opacity set to 25%, all events unbound

location.reload();

}

}

});

$("#wsdialog").dialog("option", "width", 275);

$("#wsdialog").dialog("option", "height", 175);

$("#wsdialog").dialog("option", "resizable", false);

$("#wsdialog").css("background-color", "orange");

$("#wsdialogimg").children('img').attr('src','/images/alert-icon.png');

$("#wsdialogtxt1").text("Cierre de Día en proceso.");

$("#wsdialogtxt2").text("Favor de reintentar más tarde.");

$("#wsdialog").dialog("open");

}

}

else if (params["EOD"]=="Abort") {

location.reload();

}

}


The params thing was a last resort effort, and still doesn't work.
Any pointers?
Thanks!

admin 10/13/2017

The typical way in Javascript to ask for a confirmation is to use confirm() function:

https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm

M
Molasar author 10/16/2017



The typical way in Javascript to ask for a confirmation is to use confirm() function:

https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm


Even if the user selects Cancel, the Server side still fires.
Any thoughts?

Pete K 10/17/2017



Even if the user selects Cancel, the Server side still fires.
Any thoughts?


Simple. Just return false in the OnBefore() function if you don't want the other events to fire:

return false;