GridView and delete problems with page refresh

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J055

    GridView and delete problems with page refresh

    Hi

    I have a GridView which includes the ability to delete rows. This works fine
    accept for when a naughty user decides to refresh the browser thereby
    posting the same delete command instruction. The problem with this is that
    the refresh will either delete another record or generate an exception,
    something like this:

    An error has occurred because a control with id
    'ctl00$Main$Use rGrid$ctl11$ctl 00' could not be located

    The first scenario is unwelcome but the second is very nasty because it's
    then very difficult for the user to remedy the situation. It's easy to see
    why this is happening because the post data for the delete command contains
    the index of the row and then matches it to a CommandArgument held in the
    viewstate (I think). In my case the CommandArgument contains the PrimaryKey
    ID of the record being deleted so when I refresh the page I am deleting the
    record which takes the previous record's place, if one exists, else I get
    the above error.

    Is there a way to handle this better? How do I make this more robust? What
    is actually happening in the page life cycle and the viewstate when I delete
    a record?

    In the old days you would sent the record ID with the get/post request. Why
    can't we make the GridView do this?

    Cheers
    Andrew


  • Walter Wang [MSFT]

    #2
    RE: GridView and delete problems with page refresh

    Hi Andrew,

    Thank you for your post!

    You can take a look at following article to see a possible solution:

    #Build Your ASP.NET Pages on a Richer Bedrock
    Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.

    x?pull=/library/en-us/dnvs05/html/bedrockaspnet.a sp

    It uses a custom HTTP module to intercept the HttpApplication 's
    AcquireRequestS tate event and checks if this is a duplicated POSTBACK
    caused by Refresh.

    Please feel free to post here if you need more help.

    Regards,
    Walter Wang
    Microsoft Online Community Support

    =============== =============== =============== =====
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    =============== =============== =============== =====

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Comment

    Working...