Firing a server-side method via PageMethod
<p>I wrote a JavaScript function that fires when the user clicks OK in a RadConfirm dialog.  This is supposed to trigger a JavaScript callback to the server to delete a record from the database.  This may not be the best architecture (I can think of other ways to accomplish my goals) but I'm trying to struggle through this as a learning exercise.  Below is the code I've written thus far.  I think I've gotten most of it correct.</p>

<p>This Javascript function:</p>

<pre><code>        function confirmCallBackFn(arg) {

        if (arg == true) {
            PageMethods.RemovePackagePageMethod();
        }
        else {
        }
    }
</code></pre>

<p>Should invoke the following WebMethod on the server:</p>

<pre><code>    [WebMethod()]
public static void RemovePackagePageMethod(object sender, EventArgs e)
{
    Inventory inv = new Inventory();
    inv.RemovePackage();

}
</code></pre>

<p>Which in turn should execute the following method:</p>

<pre><code>    private void RemovePackage()
{
    SBMData2.SBMDataContext db = new SBMData2.SBMDataContext();

    var boxes = from p in db.Packages
                where p.PackageID == Convert.ToInt32(RadGrid1.SelectedValues["PackageID"].ToString())
                select p;

    foreach (var box in boxes)
    {
        db.Packages.DeleteOnSubmit(box);
    }

    try
    {
        db.SubmitChanges();
        RadGrid1.Rebind();
    }
    catch (Exception ex)
    {
        RadWindowManager1.RadAlert("System error deleting package", 200, 200, "exception", null);

    }

}
</code></pre>

<p>Everything looks good to me and seems to be consistent with the posts I've read on this site and others about using PageMethod to fire code on the server.  However, it's failing to execute the deletion in the final method (which I've tested in isolation).  Can someone spot where I went wrong?</p>
