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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:09:49+00:00 2026-06-07T12:09:49+00:00

This probably looks like a duplicate but I don’t think so. I have already

  • 0

This probably looks like a duplicate but I don’t think so. I have already searched stackoverflow, may be not enough.

Here is my challenge:

<asp:LinkButton runat="server" ID="DeleteRow" CommandName="deleterow" 
   CommandArgument='<%# Eval("ID") %>' Text="Delete" 
   OnClientClick="return confirm('Are you sure you want to delete this record?');" /> 

If you click the link the first time, OnRowCommand is not fired. When you click it the second time, it works.

I looked at the source and I have these differences.

//When you first load the page: the GUID is the PK for that row 
1. javascript:__doPostBack('ctl00$content$gvSchoolClasses$58fd1759-f358-442e-bf73-2e9cedfc27e8$DeleteRow','')

//After the link was clicked the first time, the link changed and the ID empty, but works
2. javascript:__doPostBack('ctl00$content$gvSchoolClasses$ctl02$DeleteRow','')

I copied the two codes from the href of the asp:LinkButton for BEFORE and AFTER click.

What is wrong? I only have one other event on my page RowDataBound.

  protected void gvSchoolClasses_RowDataBound(object sender, GridViewRowEventArgs e)
  {
        e.Row.ID = Guid.NewGuid().ToString();
  }

  protected void Page_Load(object sender, EventArgs e)
  {
        CheckAuthentication();

        if (!Page.IsPostBack)
        {
            ClassesAcademicYearLabel.Text = "- Year " + Setting.Year;
            //FillClassesList();  //filling some combo boxes. Have checked the codes here too
            //FillLettersList();  //they didn't affect the Grid
            FillGrid();
        }

        ClassErrorLabel.Visible = false;

  }
  • 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-07T12:09:51+00:00Added an answer on June 7, 2026 at 12:09 pm

    By setting the ID property of the row in the RowDataBound event, you’ve created the problem you’re observing.

    Since the RowDataBound event isn’t fired until after the page’s controls have already been added to the collection, ASP.NET doesn’t have a way to update the already-computed client references. Hence, the command doesn’t get fired in the way you’re expecting.

    I’ve noticed that you’re already setting the CommandArgument property to the ID generated in the RowDataBound event, which could also be part of your problem (depends on order of events firing; I don’t have a pipeline chart handy).

    EDIT: a quick fix for this could be to simply set the ClientID properties (sorry, not the exact name, but intellisense should get you the rest of the way to it) to some sort of Manual, not Auto determination. That way, the ID you set is never changed by the framework.

    To elaborate a bit more on why you’re seeing this problem, consider the client-side id’s presented:

    ctl00$content$gvSchoolClasses$ctl02$DeleteRow

    This ID is guaranteed to be unique (for this page) by taking the declared ID (DeleteRow) and successively walking UP the control hierarchy and prepending parent ID’s to the string. JS code can be confident that passing this string to getElementById will behave in a consistent, predictable manner.

    In order to be able to generate said ID, all of the controls in the hierarchy must already be present and accounted for by the rendering engine.

    Now let’s consider what happens when that the ID property of a control is changed (note this is not the ClientID, but simply the property with a name of ID).

    ctl00$content$gvSchoolClasses$58fd1759-f358-442e-bf73-2e9cedfc27e8$DeleteRow

    You’ll note that instead of the row’s naming container (cl02), it now has the GUID you generated and assigned to it. Client JS attempting to access this container using the previously assigned ID will be disappointed, since it will no longer work as expected!

    When an ASP.NET control fires a post-back via a call to javascript:__doPostBack('ctl00$content$gvSchoolClasses$58fd1759-f358-442e-bf73-2e9cedfc27e8$DeleteRow','')

    the post-back will occur just fine and dandy, but (and you can verify this by inspecting the form params of the postback) when the server processes the request, it will attempt to rehydrate (from viewstate) a control that doesn’t exist. Consequently, it will create a new instance of the control (with the correct ID) which has no idea that a command has been issued, so the XXXCommand event(s) are never fired. Since databinding isn’t happening (it’s a postback, and your code correctly checks for that condition), the ID is never reset, and the command can be fired normally

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Probably a very trivial problem. I have an object that looks like this: @PersistenceCapable
Sorry, I know this is probably a duplicate but having searched for 'python regular
This probably sounds like a terrible idea at first glance, but here is my
I know this probably really simple but Im not sure what im doing wrong...
I feel like this question has probably been asked a thousand times already, so
This question probably looks a lot like IDE for ironpython on windows question here
I have a MySQL database that looks like this: users ( id , name
This is probably obvious, but I'm a bit of a newbie and have spent
I have a PHP array that I'd like to duplicate but only copy elements
This is probably a shot in the dark but here goes nothing... I have

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.