This is a migrated thread and some comments may be shown as answers.

Page Refresh Makes One More Entry In a Database

1 Answer 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 31 Jul 2011, 11:37 AM
Hi,

I am using telerik grid and editfromtemplate, and what happen is that whenever I refresh the page after inserting a record in telerik grid. It makes one more entry in the grid and in the database. I want to prevent this behaviour of grid because it's causing duplicate number of records in my grid.

Imports Telerik.Web.UI
 
Partial Class SNR_Config
    Inherits System.Web.UI.UserControl
 
    Private dbContext As New SNRDentonDBLayerDataContext
 
   Protected Sub rgConfiguration_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgConfiguration.NeedDataSource
 
        BindGrid()
 
    End Sub
 
    Protected Sub BindGrid()
 
        Dim IConfig = From Config In dbContext.SNR_Configurations Order By Config.ID Descending
              Select Config
 
        rgConfiguration.DataSource = IConfig.ToList
 
 
    End Sub
 
 
    Protected Sub rgConfiguration_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgConfiguration.ItemCommand
 
        If e.CommandName = RadGrid.PerformInsertCommandName Then
            Insert(e)
        ElseIf e.CommandName = RadGrid.UpdateCommandName Then
            Update(e)
        ElseIf e.CommandName = "Delete" Then
            Delete(e)
        End If
 
    End Sub
 
    Protected Sub Insert(ByVal e As Telerik.Web.UI.GridCommandEventArgs)
 
        If TypeOf e.Item Is GridEditFormInsertItem AndAlso e.Item.IsInEditMode Then
 
            If e.Item.OwnerTableView.IsItemInserted Then
 
                Dim txtKey As TextBox = e.Item.FindControl("txtKey")
                Dim txtValue As TextBox = e.Item.FindControl("txtValue")
                Dim chkIsAdmin As CheckBox = e.Item.FindControl("chkIsAdmin")
 
                Dim con As New SNR_Configuration
                con.ConfigKey = txtKey.Text.Trim
                con.ConfigValue = txtValue.Text.Trim
                con.CreatedOn = DateTime.Now
                con.CreatedBY = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo.UserID
                con.IsDeleted = False
                con.IsAdmin = IIf(chkIsAdmin.Checked, True, False)
 
                dbContext.SNR_Configurations.InsertOnSubmit(con)
                dbContext.SubmitChanges()
 
            End If
 
        End If
 
    End Sub
 
    Protected Sub rgConfiguration_ItemDataBound(ByVal source As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgConfiguration.ItemDataBound
 
 
        If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then
 
            If TypeOf e.Item Is GridEditableItem And TypeOf e.Item Is GridEditFormInsertItem Then
 
                Dim btnInsert As Button = e.Item.FindControl("btnInsert")
                btnInsert.Visible = True
 
            Else
 
                Dim btnUpdate As Button = e.Item.FindControl("btnUpdate")
                btnUpdate.Visible = True
 
            End If
 
        End If
 
 
    End Sub
    
 
 
 
End Class

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 04 Aug 2011, 12:33 PM
Hello Muhammad,

I assume you mean refreshing by pressing the F5 key. If so, the problem is a browser one and not directly related to RadControls.

I would advise you to follow these links (and if not satisfied with the suggestions, google for other ones on how to prevent pressing F5 from repeating the last request):
http://www.domainwebcenter.com/?p=187
http://forums.asp.net/t/734940.aspx/1

All the best,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Muhammad
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or