Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8540217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:32:50+00:00 2026-06-11T11:32:50+00:00

i have a problem. I am trying to delete something from a list but

  • 0

i have a problem. I am trying to delete something from a list but it never calls my delete function from the .aspx.cs

here is my javascript code:

function doTheDelete(doIDeleteExpenses) {
        if (selectedExpensesList.length > 0) {
            $.ajax({
                type: "POST",
                //url: "/Tasks/ViewTasks.aspx/deleteTasksAndLinkedItems",
                url: '<%=ResolveUrl("~/Expenses/ViewExpenses.aspx/deleteSelectedExpense")%>',
                data: "{'DeleteExpenses' : " + "'" + doIDeleteExpenses + " '}",
                //dataaaaaa
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var ss = data.d;
                    if (ss.length > 0) {
                        for (var i = 0; i < ss.length; ++i) {
                            $.noty.consumeAlert({ layout: 'center', type: 'error', dismissQueue: true });
                            alert(ss[i]);

                        }
                    }
                    $("#viewTasksGrid").flexReload();
                },
                error: function (data) {
                    $.noty.consumeAlert({ layout: 'center', type: 'error', dismissQueue: true, modal: true });
                    alert('Error Deleting Expense');
                    if (window.console) {
                        console.log(data);
                    }
                }
            });
        } else {
            showMessage('No expenses are selected.');
        }
    }

    function getSelectedExpenseIDs() {
        var selectedExpensesList = new Array;
        var i = 0;
        $('.expenseCheckBox:checked').each(function () {
            if ($(this)[0].id !== "checkAllExpenses") {
                selectedExpensesList[i] = $(this)[0].id.split('_')[1];
                ++i;
            }
        });
        return selectedExpensesList;
    }

and here is my method in the aspx.cs that never gets called:

[WebMethod]
public static string[] deleteSelectedExpense(bool DeleteExpenses, String[] ExpID)
{
    var rList = new List<string>();
    //var canDeleteTasks = false;
    //var canDeleteTrackers = false;
    var canDeleteExpenses = false;
    var investigatorID = (int)HttpContext.Current.Session["InvestigatorID"];
    var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["OSCIDConnectionString"].ToString());
    var cmd = new SqlCommand("p_Admin_Permissions_CanDeleteExpenses", conn);
    cmd.Parameters.Add(new SqlParameter("@InvestigatorID", SqlDbType.Int));
    cmd.Parameters["@InvestigatorID"].Value = investigatorID;
    cmd.CommandType = CommandType.StoredProcedure;
    try
    {
        conn.Open();
        canDeleteExpenses = (bool)cmd.ExecuteScalar();
    }
    catch (SqlException sql)
    {
        if (!rList.Contains("Can not connect to the database. Please try again."))
            rList.Add("Can not connect to the database. Please try again.");
    }
    catch (Exception ex)
    {
        if (!rList.Contains("An Error Occured"))
            rList.Add("An Error Occured");
    }
    finally
    {
        if (conn.State == ConnectionState.Open)
            conn.Close();
    }

    if (canDeleteExpenses)
    {
        foreach (var expense in ExpID)
        {

            if (canDeleteExpenses && DeleteExpenses)
            {
                conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ToString());
                cmd = new SqlCommand("p_DeleteExpenses", conn);
                cmd.Parameters.Add(new SqlParameter("@TaskID", SqlDbType.Int));
                cmd.Parameters["@ExpID"].Value = int.Parse(expense);
                cmd.Parameters.Add("@Message", SqlDbType.NVarChar, 50);
                cmd.Parameters["@Message"].Direction = ParameterDirection.Output;
                cmd.CommandType = CommandType.StoredProcedure;
                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
                catch (SqlException sql)
                {
                    if (!rList.Contains("Error Connecting to the Database. Unable To Delete Expense(s)."))
                        rList.Add("Error Connecting to the Database. Unable To Delete Expense(s).");
                }
                catch (Exception ex)
                {
                    if (!rList.Contains("An Error Occured"))
                        rList.Add("An Error Occured");
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                        conn.Close();
                }
            }
            else if (!canDeleteExpenses && DeleteExpenses)
            {
                rList.Add("You do not have permission to delete Expenses");
            }
            else
            {
                if (!rList.Contains("You do not have permission to delete the task(s)."))
                    rList.Add("You do not have permission to delete the task(s).");
            }
        }
    }
    //var serializer = new JavaScriptSerializer();
    //var re = serializer.Serialize(rList.ToArray());
    return rList.ToArray();
}

When I am in the browser console, it tells gives me an internal error(500). Well for obvious reasons.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:32:51+00:00Added an answer on June 11, 2026 at 11:32 am

    Your parameters are wrong. The deleteSelectedExpense method takes bool and string[] parameters, but you’re only passing it the bool to flag wether to delete them.

    EDIT: You’re not passing your string array properly I’m guessing. When passing the array of string values, the json format should look like expId : [ 1, 2, 3 ], which is why I’m using the myArray.join method and placing the brackets around the values.

    var myArray = ['100', '200'];
    $.ajax({
             type: 'POST',
             url: 'WebForm1.aspx/testMethod',
             contentType: 'application/json; charset=utf-8',
             dataType: 'json',
             data: '{ del: true, expId : [' + myArray.join(",") + '] }',
             success: success,
             error: error
           });
    function success(data) {
        $('#result').html(data.d);
    }
    function error(data) {
        $('#result').html(data.d);
    }
    

    WebMethod:

    [WebMethod]
    public static string testMethod(bool del, string[] expId)
    {
        var rand = new Random();
        return rand.Next().ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make functionality for deleting column from grid, but I have problem
I have a problem trying to turn my python code into an executable using
I have a problem trying to hide .php extension from the url I have
I am trying something very basic: I have a list of 5 buttons. They
I am trying to delete a string from a string, but the result of
I'm trying to implement a simple TPH example from http://msdn.microsoft.com/en-us/library/dd793152.aspx . I have two
I have a problem trying to register my own Event/Listener to the event dispatcher.
I have a problem trying to design some generic storage.. Basically I have the
I have a problem trying to edit. I work with Areas for better management
I implemented the table sorter yesterday and i have a problem trying to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.