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 8842897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:04:55+00:00 2026-06-14T11:04:55+00:00

I have a page which lists a bunch of items in a datagrid. Each

  • 0

I have a page which lists a bunch of items in a datagrid.

Each item has a cooresponding remove link button, 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.

My code looks like the following:

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

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

In my code behind, my event handler looks like such:

   private List<MyItem> _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(@"<script language='javascript'>alert('HERE');</script>");
           //Page.ClientScript.RegisterStartupScript(this.GetType(), "hwa", "alert('Hello World');", true);

      }
   }

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

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…

Is it possible to do something like this:

in MyFile.js

var GetAlertMessage = function()
{
    alert("Can't delete this item");
}

and call this function in my C# function that I listed above?

Thanks in advance for the help.

  • 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-14T11:04:57+00:00Added an answer on June 14, 2026 at 11:04 am

    You should treat this like any other validation routine. There should be a client-side validation function and a server-side validation function.

    Client Side Validation

    on each delete-able item, add an onclick="ValidateDeletion();" and class="deleteable-item"

    function ValidateDeletion()
    {
        var itemCount = $(".deleteable-item").length;
        if(itemCount == 1)
        {
            alert("Sorry, you cant delete this item.")
            return false;
        }
        else
        {
            //let it pass through
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm constructing an ecommerce application in Symfony, and I have a page which lists
I have a page with a list of elements display (items) - which are
I have a page-scoped component, which has an instance variable List with data, which
I have a page on my site which has multiple drop down boxes as
I have a page which lists all the files in a particular folder (all
I need to build a web page with a DetailsView which has a bunch
We currently have a quote page which lists all existing quotes that we would
me again, I have a current page containing a usercontrol which lists buildings. Here
I have a page that lists a bunch of files. This page can be
So I have a gridview which lists a bunch of jobs. On this gridview

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.