I've searched around for a solution to this problem. Below is a representation of my pseudocode:
bool hasData = ItemHasData(itemid);
Confirm = "false"; // hidden variable
if (hasData)
{
//Code to call confirm(message) returns "true" or "false"
if (Confirm == "true")
{
//Delete item
}
else if (Confirm == "false")
{
return;
}
}
The code calling the confirm function uses an asp:Literal control and assigns it the value of the confirmation message. I am able to display the popup, however, it only appears after the execution of the function and does not handle subsequent conditions.
The general consensus is that invoking JavaScript at that specific line is unachievable due to the gap between server-side and client-side operations. How can I work around this? I attempted using the ConfirmButtonExtender from the ASP.NET AJAX Toolkit but encountered issues interacting with the object in the code behind when it is set to runat="server".
Edit:
Apologies for missing those details. Much appreciated, Icarus.
The control in question is the GridView (the pseudo version actually pertains to the gvData_RowCommand function)'s rowcommand. The initial check confirms whether the CommandName is DeleteItem, triggering subsequent actions.
The columns in gvData are determined by a list of headers and dataset; the table caters to multiple items with varying required information. While the data is present, I need a Yes/No (or, more realistically, Ok/Cancel) dialog to confirm deletion intentions when there is existing data.