C# OnCommand Call Alert Box
<p>I have a page which lists a bunch of items in a datagrid. </p>

<p>Each item has a cooresponding <code>remove link button</code>, which removes the item from the list. In my event handler -- where the item is deleted -- I do a check to see if the item is the last item in the list. If it is the last item, I don't do a delete, but send an alert box telling the user that the item cannot be deleted. I am unsure how to get C# to trigger  this alert box. </p>

<p>My code looks like the following:</p>

<p>In my aspx, I have a datagrid with various Link Buttons. Snippet of code as shown:</p>

<pre><code>&lt;ItemTemplate&gt;
    &lt;asp:LinkButton runat="server" ID="Remove"
                OnCommand="lnkRemove_Command" CommandArgument='&lt;%# Eval("Id") %&gt;
                OnClientClick="return false;"&gt;
    &lt;/asp:LinkButton&gt;
&lt;/ItemTemplate&gt;
</code></pre>

<p>In my code behind, my event handler looks like such:</p>

<pre><code>   private List&lt;MyItem&gt; _items;

   protected void lnkRemove_Command(object sender, CommandEventArgs e)
   {
      int ID = Convert.ToInt32(e.CommandArgument);
      MyItem item = MyItem.GetItemByID(id); //This gets the item cooresponding to the ID
      if (_items.Count != 1) 
      {
          //code to delete item   
      }
      else
      {
           //Generate an alert box to tell the user that this item cannot be deleted.
           //I have tried the following two lines of commented code, which didn't work for me
           //Response.Write(@"&lt;script language='javascript'&gt;alert('HERE');&lt;/script&gt;");
           //Page.ClientScript.RegisterStartupScript(this.GetType(), "hwa", "alert('Hello World');", true);

      }
   }
</code></pre>

<p>In addition, it may be important to note that in my <code>Page_Load</code>, I already do a <code>Context.RegisterResource(this, StyleSheet, Script)</code>. In other words, I have working JavaScript and CSS, which cooresponds with this code for other features of this page in MyFile.js</p>

<p>If possible, I would like to create a JS function in MyFile.js where I already have js functions which are triggered by various OnClientClicks, etc...</p>

<p>Is it possible to do something like this:</p>

<pre><code>in MyFile.js

var GetAlertMessage = function()
{
    alert("Can't delete this item");
}
</code></pre>

<p>and call this function in my C# function that I listed above?</p>

<p>Thanks in advance for the help.</p>
