Question

The situation is a user can add modules to their profile, upon adding a row they are redirected to a page containing a gridview. The gridview displays all their currently selected modules. Each row of the gridview contains a "delete" button which allows the user to delete a module from their profile. Users have no problem deleting modules if the gridview row count > 1. However when only one row remains in the table then pressing the "delete" button does not remove the row. The only way to delete the row is to logout and log back in again. I do not understand why this happens. I am sure that it is not a problem with the stored procedure as i have manually executed the sp and have been able to delete rows from the table, no matter how many rows remain.

Here is the code executed upon button press:

else if (e.CommandName == "Remove")
            {
                //deleteUserModule
                Debug.WriteLine("userID: " + userID + ", code: " + moduleCode);
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CMS"].ConnectionString))
                {
                    using (SqlCommand cmd = new SqlCommand("deleteUserModule", conn)
                        {
                            CommandType = CommandType.StoredProcedure
                        })
                    {
                        cmd.Parameters.Add(new SqlParameter("@moduleCode", SqlDbType.NVarChar)).Value = moduleCode;
                        cmd.Parameters.Add(new SqlParameter("@userID", SqlDbType.Int)).Value = userID;
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        cmd.Dispose();
                        conn.Dispose();
                    }
                }
                moduleCode = String.Empty;
                Page.Response.Redirect(Page.Request.Url.ToString(), true);
            }

Any suggestions as to why the final row can only be deleted after a logout and log back in?

UPDATE: After checking out the exception thrown, thanks to the advice of @BrendanGreen, i have changed the refresh statement from:

Page.Response.Redirect(Page.Request.Url.ToString(), true);

To:

Response.Redirect("myModules.aspx", false);
                Context.ApplicationInstance.CompleteRequest();

The problem no longer persists

Was it helpful?

Solution

After checking out the exception thrown, thanks to the advice of @BrendanGreen, i have changed the refresh statement from:

Page.Response.Redirect(Page.Request.Url.ToString(), true);

To:

Response.Redirect("myModules.aspx", false);
            Context.ApplicationInstance.CompleteRequest();

The problem no longer persists

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top