Share via

in asp i use a GridView by Click the Edit Buton On Eact Row, it runing first the page_init, and page_Load,Page_PreRender And the

Simon 491 Reputation points
2026-02-22T21:15:26.0566667+00:00

in asp i use a GridView it is coneteted To Sql, it have a EditButon On Eact Row, but i figerd the by clicking the Edit Button, it first running the page_init, and page_Load,Page_PreRender and the edit dont run, is it posible to fix this?

Developer technologies | ASP.NET | Other
0 comments No comments

Answer accepted by question author
  1. Bruce (SqlWork.com) 83,666 Reputation points
    2026-02-23T17:34:09.35+00:00

    This is how webform server controls work. The button does a form post, the server runs the postback page lifecycle and rerenders the page, and the browser display the new page.

    if you used an update panel, you still get the full page cycle, but only the update panel html is returned.

    the only alternative to the full page cycle is to use a client (JavaScript) control instead of a server control.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Jack Dang (WICLOUD CORPORATION) 16,115 Reputation points Microsoft External Staff Moderator
    2026-02-23T04:24:36.99+00:00

    Hi @Simon ,

    Thanks for reaching out.

    When you click the Edit button in a GridView, the page performs a full postback. That means it will go through the normal page lifecycle again - Page_Init, then Page_Load, then the GridView’s Edit event, and finally Page_PreRender.

    So it’s completely normal that Page_Init and Page_Load run first.

    Now, if your Edit action doesn’t seem to work, a possible reason is that the GridView is being rebound on every Page_Load. When you rebind the GridView without checking IsPostBack, it resets the control state, which cancels the edit mode before it can render.

    Make sure your data binding is wrapped like this:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGrid();
        }
    }
    

    And your Edit handler should look something like:

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        BindGrid();
    }
    

    Please treat the code above as a reference example, you’ll need to adjust the method names, control IDs, and binding logic to match your actual project structure.

    Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.

    0 comments No comments

  2. AgaveJoe 31,186 Reputation points
    2026-02-22T22:49:48.23+00:00

    The GridView provides built-in tools for inline editing, but it can be difficult to diagnose the exact issue without seeing your markup and code-behind.

    Generally, this behavior occurs if the data is being rebound on every postback, which prevents the edit command from processing. I recommend reviewing the official ASP.NET GridView tutorials to ensure the RowEditing and RowUpdating events are implemented correctly:

    GridView Editing Tutorial

    0 comments No comments

  3. Q&A Assist
    2026-02-22T21:15:35.7866667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    When using a GridView in ASP.NET, the typical lifecycle events such as Page_Init, Page_Load, and Page_PreRender are executed in sequence during a postback. If you find that clicking the Edit button does not trigger the expected editing behavior, it may be due to how the GridView is configured or how the event handlers are set up.

    Here are some steps to troubleshoot and potentially fix the issue:

    1. Ensure Event Handlers are Properly Set: Make sure that the event handler for the GridView's RowEditing event is correctly wired up in your code-behind. This is where you should set the EditItemIndex and rebind the GridView.
         protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) {
             GridView1.EditIndex = e.NewEditIndex;
             BindGrid(); // Method to rebind your GridView data
         }
      
    2. Data Binding: Ensure that you are rebinding the GridView after setting the EditItemIndex. This is crucial because the GridView needs to refresh its data to reflect the edit mode.
    3. Check ViewState: If ViewState is disabled for the GridView, it may not retain the state of the control across postbacks. Ensure that ViewState is enabled for the GridView.
    4. Postback Handling: If you have other controls on the page that may be causing a postback, ensure that they are not interfering with the GridView's postback. You can check if the GridView is being updated correctly by debugging the page lifecycle.
    5. Check for Errors: Look for any exceptions or errors in your code that might prevent the GridView from entering edit mode. You can use try-catch blocks to catch exceptions and log them for further investigation.

    By following these steps, you should be able to diagnose and fix the issue with the GridView not entering edit mode as expected when the Edit button is clicked.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.