title: Conditional confirm prompt in asp.net code behind
body: <p>I have looked around for a way of implementing this. Here is a pseudocode representation of what I have:</p>
  
  <pre><code>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;
      }
  }
  </code></pre>
  
  <p>The code to call confirm uses a asp:Literal control and sets it equal to the confirm. I can get the popup but only after the function exits. And it does nothing with the conditions after that.</p>
  
  <p>The general consensus seems to be that calling the javascript at that specific line is impossible (makes sense due to the server side/client side gap), but how can I achieve this? I tried using the ConfirmButtonExtender from the ASP.NET AJAX Toolkit but I couldn't interact with the confirmbuttonextender object from the code behind when the object is set to runat="server".</p>
  
  <p>edit:</p>
  
  <p>Sorry, I did miss those tidbits. Thanks Icarus.</p>
  
  <p>The control itself is the GridView (the pseudo version is actually from the gvData_RowCommand function)'s rowcommand. The first check looks to see if the CommandName is DeleteItem and if so goes into this.</p>
  
  <p>The gvData's columns are set based off a list of headers (and the dataset) passed as the table it is working against is for multiple items with different required information. The gvData's data is there, I just need to get a Yes/No (or in reality it'll end up being Ok/Cancel) dialog to verify they want to delete the item when there is data.</p>