473,320 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

VB.NET (web) gridView sends delete command twice?

32
Hello!

In VB.NET I have a GridView that shows a list of dates and beside each date there's a delete button.

For a reason I don't know, the delete event seems to be fired twice, but I have trouble finding the exact source of the problem.

From this thread : http://bytes.com/forum/threadnav436365-1-10.html, I have set my command button as a template field and call "GridView1.DeleteRow(Int32.Parse(e.CommandArgument .ToString()))" when the button is clicked.

Just above that line, I call a method that logs whatever I want : Logger("[DEBUG] ImageButton1_Command"). In the log file, I see only one entry, as if the block of code is executed only once.

But when I use SqlProfiler to see what's happening at the server's level, I see that my stored procedure is called twice because I have two following line two times :
exec pln_add_exception @date='2008-09-07 00:00:00:000',@planification_id=9


......

My VB code :

Expand|Select|Wrap|Line Numbers
  1. Protected Sub ImageButton1_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
  2.         Logger("[DEBUG] ImageButton1_Command")
  3.         GridView1.DeleteRow(Int32.Parse(e.CommandArgument.ToString()))
  4. End Sub
  5.  
  6.  
  7. Private Sub Logger(ByVal message As String)
  8.         Dim logEntry As New LogEntry()
  9.         logEntry.EventId = 100
  10.         logEntry.Priority = 1
  11.         logEntry.Title = "Logging message"
  12.         logEntry.Message = message
  13.         logEntry.Categories.Add("General")
  14.         Logger.Write(logEntry)
  15. End Sub
  16.  
My GridView :
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlServerExecutionsPlanifiees" DataKeyNames="date" EnableViewState="False">
  2.    <Columns>
  3.       <asp:TemplateField HeaderText="date" SortExpression="date">
  4.          <ItemTemplate>
  5.             <asp:Label ID="dateLabel" runat="server" Text='<%# Eval("date", "{0:d}") %>' CssClass='<%# "planifDate" & CType(Eval("planifie"), String) %>'></asp:Label>
  6.          </ItemTemplate>
  7.       </asp:TemplateField>
  8.       <asp:TemplateField>
  9.          <ItemTemplate>
  10.             <asp:ImageButton runat="server" id="ImageButton1" CommandName="Delete" ImageUrl="images/delete.png" CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>' OnCommand="ImageButton1_Command" />
  11.          </ItemTemplate>
  12.       </asp:TemplateField>
  13.    </Columns>
  14. </asp:GridView>
  15.  
Sep 3 '08 #1
3 2506
balabaster
797 Expert 512MB
In the Sql Profiler, is one line referencing the begin process and one line referencing the end of process? One of my colleagues complained of this last week and he was reading the Sql Profiler wrong - turns out what he thought were "two calls" were in fact two records describing the begin and the end of the same process...
Sep 3 '08 #2
myth0s
32
In the Sql Profiler, is one line referencing the begin process and one line referencing the end of process? One of my colleagues complained of this last week and he was reading the Sql Profiler wrong - turns out what he thought were "two calls" were in fact two records describing the begin and the end of the same process...
I doubt it.

There's the following line between the two calls :
exec sp_reset_connection

And each call says "RPC: Completed" and "Reads: 3" (the number of reads is good, but it should do so only one time).

What I am trying to find right now is a way to know what happens "between" the Web App and SQL Server. If I could know where the problem comes from, that would helpful!!
Sep 3 '08 #3
myth0s
32
I've added logging methods everywhere I could and :

This is called once :
Expand|Select|Wrap|Line Numbers
  1. GridView1.DeleteRow(Int32.Parse(e.CommandArgument.ToString()))
  2.  
Expand|Select|Wrap|Line Numbers
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2. ....
  3.  

But at the server side my stored procedure gets called twice :

Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE [production].[pln_ajouter_exception]
  2. @date AS SMALLDATETIME,
  3. @planification_id AS BIGINT
  4. AS
  5. ....
  6.  
  7. INSERT INTO production.test (texte, temps)
  8. VALUES ('@nbException : ' + CAST(@nbException AS Nvarchar(max)), GETDATE())
  9.  
  10. ...
  11.  
This is two records in in test table (the date is the same). There should be only one.

EDIT : I may add that I do not fully understand how my grid view behaves. When I click on the delete button, the page is sent back to the server. I thought that the delete procedure (set in the grid view's propreties) get executed and then the page is rendered again (meaning that the select procedure is executed).

What I see when I look in the SQL Profiler is this :
Expand|Select|Wrap|Line Numbers
  1. 1. exec sp_executesql N'SELECT TOP 30  [date], planifie FROM plnv_tous_evenements WHERE ([id] = @id) ORDER BY date',N'@id bigint',@id=9
  2. 2. exec sp_reset_connection 
  3. 3. exec pln_ajouter_exception @date='2008-09-07 00:00:00:000',@planification_id=9
  4. 4. exec sp_reset_connection 
  5. 5. exec pln_ajouter_exception @date='2008-09-07 00:00:00:000',@planification_id=9
  6. 6. exec sp_reset_connection
  7. 7. exec sp_executesql N'SELECT TOP 30  [date], planifie FROM plnv_tous_evenements WHERE ([id] = @id) ORDER BY date',N'@id bigint',@id=9
  8.  
What is going on?? From my understanding, I should only see steps 5 to 7..... shouldn't I?
Sep 4 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: NateDawg | last post by:
Ok, I’ve noticed a few gridview problems floating around the forum. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state...
9
by: J055 | last post by:
Hi I have a very simple configuration of the GridView with paging and sorting. When I do a postback the DataBinding event fires twice - in both the ProcessPostData and PreRender stages of the...
0
by: DC | last post by:
Why would this code give me the error "Could not load type System.Web.UI.WebControls.AccessDataSource from assembly System.Web, Version=1.0.5000.0" at line 16... <form id="form1"...
3
by: tarscher | last post by:
Hi all, I have a grid that contains 7 columns from 3 tables (3 unique keys, 4 normal fields). I show this 7 columns on the gridview. I now want to add edit and delete functionality. This should...
2
by: Deere | last post by:
Keep in mind I'm an old guy who is learning .net. In asp classic I had a trash can icon in my shopping cart that would delete a record. In trying to accomplish the same in gridview I've used a...
4
by: Wannabe | last post by:
I am using ASP.Net 2.0 and have a gridview on my page. I have everything working except the delete command. The page reloads except the row I am trying to delete is still there. I believe it is...
0
by: Wannabe | last post by:
I am using ASP.Net 2.0 and have a gridview on my page. I have everything working except the delete command. The page reloads except the row I am trying to delete is still there. I believe it is...
1
by: Barry L. Camp | last post by:
Hi all, Wondering if someone can help with a nagging problem I am having using a GridView and an ObjectDataSource. I have a simple situation where I am trying to delete a row from a table, but...
0
by: Larry Bud | last post by:
After spending two days looking at the options in adding a row to a gridview, I came up with my own that I'd like to share. I only can share pseudo-code right now, but maybe in the future I'll...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.