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

Duplicate records as user double clicks on Insert link button of the grid

5 Answers 1073 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tina
Top achievements
Rank 1
Tina asked on 22 Apr 2013, 08:01 PM
Hi,

I want to avoid double clicks on the Insert button as it cause duplicate entry.
I have checked in the InsertCommand event that the user clicked twice but if I cancel the event - none of the entry is saved to the DB.

How can I avoid this?

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Apr 2013, 04:42 AM
Hi,

One suggestion is that you can set the field as a primary key and then check for duplicate data in the InsertCommand as explained in the following demo.
Grid - Entity Framework Manual Operations

Thanks,
Shinu
0
Tina
Top achievements
Rank 1
answered on 23 Apr 2013, 02:02 PM
The grid sets its data sourse in ASPX page with all the insert,delete,update,select command.

There is no code behind.

Before the postback, users in one attempt clicks INSERT button twice(double click) and hence two records are inserted with different primary key.

In insertcommand event, the control comes up twice but if I cancel the command .....no records are inserted.....I need to insert one record.

 

 

<telerik:RadGrid ID="RadGrid1" Width="75%" runat="server"

 

 

 

DataSourceID="SqlDataSource2" AllowAutomaticDeletes="True"

 

 

 

AllowAutomaticInserts="True" AllowAutomaticUpdates="True"

 

 

 

AutoGenerateColumns="False" GridLines="None" AutoGenerateDeleteColumn="True"

 

 

 

AutoGenerateEditColumn="True" ShowFooter="True"

 

 

 

OnInsertCommand="RadGrid1_InsertCommand"

 

 

 

OnItemInserted = "RadGrid1_ItemInserted"

 

 

 

onitemdatabound="RadGrid1_ItemDataBound"

 

 

 

oneditcommand="RadGrid1_EditCommand">

 

 

 

<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">

 

 

 

</HeaderContextMenu>

 

 

 

<MasterTableView CommandItemDisplay="Top" DataSourceID="SqlDataSource2"

 

 

 

DataKeyNames="id">

 

 

 

<CommandItemSettings ExportToPdfText="Export to Pdf" AddNewRecordText="Create new time entry" />

 

 

 

<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">

 

 

 

</RowIndicatorColumn>

 

 

 

<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">

 

 

 

</ExpandCollapseColumn>

 

 

 

<Columns>

 

 

 

 

<telerik:GridBoundColumn DataField="id" Visible="False" DataType="System.Int64" FilterControlAltText="Filter id column"

 

 

 

HeaderText="id" ReadOnly="True" SortExpression="id" UniqueName="id">

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

 

<telerik:GridTemplateColumn Visible="False" DataField="fk_project_id" DataType="System.Int64" FilterControlAltText="Filter fk_project_id column"

 

 

 

HeaderText="Project" SortExpression="fk_project_id" UniqueName="fk_project_id">

 

 

 

<EditItemTemplate>

 

 

 

<telerik:RadComboBox ID="fk_project_idRadComboBox" OnClientBlur="checkProjectIsOpenForBilling" runat="server" DataSourceID="sdsProjects" EmptyMessage="begin typing project# or name" Width="300px" Filter="contains" AppendDataBoundItems="true" AllowCustomText="false"

 

 

 

DataTextField="project_full" DataValueField="id" SelectedValue='<%# Bind("fk_project_id") %>'>

 

 

 

<Items><telerik:RadComboBoxItem Text="" Value="0" /></Items>

 

 

 

</telerik:RadComboBox>

 

 

 

<asp:RequiredFieldValidator ID="rfv12" runat="server" ControlToValidate="fk_project_idRadComboBox" ErrorMessage="required" />

 

 

 

</EditItemTemplate>

 

 

 

<ItemTemplate>

 

 

 

<asp:Label ID="fk_project_idLabel" runat="server" Text='<%# Eval("fk_project_id") %>'></asp:Label>

 

 

 

</ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

<telerik:GridTemplateColumn DataField="for_date" DataType="System.DateTime" HeaderText="Date" >

 

 

 

<ItemTemplate>

 

 

 

<asp:Label ID="Label1" runat="server" Text='<%# Eval("for_date", "{0:d}") %>' />

 

 

 

</ItemTemplate>

 

 

 

<EditItemTemplate>

 

 

 

<telerik:RadDatePicker runat="server" ID="for_date" DbSelectedDate='<%# Bind("for_date") %>' />

 

 

 

<asp:RequiredFieldValidator ID="rfvf" runat="server" ControlToValidate="for_date" ErrorMessage="required" />

 

 

 

</EditItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

 

 

 

<telerik:GridTemplateColumn DataField="project_number" FilterControlAltText="Filter project_number column"

 

 

 

HeaderText="Project" SortExpression="project_number" UniqueName="project_number">

 

 

 

 

<ItemTemplate>

 

 

 

<asp:Label ID="project_numberLabel" runat="server" Text='<%# Eval("project_number") %>'></asp:Label> -

 

 

 

<asp:Label ID="lblProjectTitle" runat="server" Text='<%#Eval("project_title") %>'></asp:Label>

 

 

 

</ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

<telerik:GridTemplateColumn DataField="description" FilterControlAltText="Filter description column"

 

 

 

HeaderText="Description" SortExpression="description" UniqueName="description">

 

 

 

<EditItemTemplate>

 

 

 

<asp:TextBox ID="descriptionTextBox" runat="server" Height="100px" Text='<%# Bind("description") %>'

 

 

 

TextMode="MultiLine" Width="300px"></asp:TextBox>

 

 

 

 

<asp:RequiredFieldValidator ControlToValidate="descriptionTextBox" runat="server" ID="RFV" ErrorMessage="required" />

 

 

 

 

</EditItemTemplate>

 

 

 

<ItemTemplate>

 

 

 

<asp:Label ID="descriptionLabel" runat="server" Text='<%# Eval("description") %>'></asp:Label>

 

 

 

</ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

<telerik:GridTemplateColumn Aggregate="Sum" DataField="hours" DataType="System.Decimal"

 

 

 

FilterControlAltText="Filter hours column" HeaderText="Hours" SortExpression="hours"

 

 

 

UniqueName="hours" FooterText=" ">

 

 

 

<EditItemTemplate>

 

 

 

<telerik:RadComboBox ID="hoursRadComboBox" runat="server" DataSourceID="sdsTimeIntervals" Filter="startswith"

 

 

 

DataTextField="display_value" DataValueField="time_value" SelectedValue='<%# Bind("hours") %>'>

 

 

 

</telerik:RadComboBox>

 

 

 

</EditItemTemplate>

 

 

 

<ItemTemplate>

 

 

 

<asp:Label ID="hoursLabel" runat="server" Text='<%# Eval("hours") %>'></asp:Label>

 

 

 

</ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

<telerik:GridTemplateColumn DataField="date_time" DataType="System.DateTime" FilterControlAltText="Filter date_time column"

 

 

 

HeaderText="date_time" SortExpression="date_time" UniqueName="date_time" Visible="False">

 

 

 

<ItemTemplate>

 

 

 

<asp:Label ID="date_timeLabel" runat="server" Text='<%# Eval("date_time") %>'></asp:Label>

 

 

 

</ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

</Columns>

 

 

 

<EditFormSettings>

 

 

 

<EditColumn FilterControlAltText="Filter EditCommandColumn column">

 

 

 

</EditColumn>

 

 

 

</EditFormSettings>

 

 

 

</MasterTableView>

 

 

 

<FilterMenu EnableImageSprites="False">

 

 

 

</FilterMenu>

 

 

 

</telerik:RadGrid>

 

0
Kostadin
Telerik team
answered on 26 Apr 2013, 11:06 AM
Hello Tina,

I am not exactly sure how two records are inserted when insert button is clicked twice. I prepared a small sample based on your code and attached it to this forum post. As you could see only one records is inserted. Could you please give it a try and let me know how it differs from your real setup?

Greetings,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Tina
Top achievements
Rank 1
answered on 26 Apr 2013, 08:42 PM
Hi Kostadin,

Thanks for the reply. 

The user clicks INSERT link button twice in one attempt. Enter data in the new entry record  then double click insert button.

The insert command gets fired twice hence data is inserted twice with unique ID in the table.

I debugged,if you manage to double click the control comes in twice.

Regards,
Tina 
0
Kostadin
Telerik team
answered on 01 May 2013, 01:33 PM
Hello Tina,

Could you please confirm that you are able to replicate the issue in my sample? If you succeeded could you please provide us with a video which demonstrates the needed steps of reproducing the issue? This way we will be able to investigate it further.

All the best,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Tina
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Tina
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or