473,613 Members | 2,204 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView RowCommand firing twice

4 New Member
I am using a GridView in ASP.Net 2.0 to Insert, Edit, Update and Delete. I am using ItemTemplate and EditItemTemplat e and the buttons are LinkButtons. I am inserting a new row from the footer. The RowCommand event is firing twice when I hit the Edit, Update, Delete and Insert buttons. The AutoEventWireup is set to false. What am I missing? Thanks.
May 16 '07 #1
2 11027
Mimix
1 New Member
I have a solution to this issue that is probably the cleanest I have seen. I will allow you to make the fewest changes to your code and continue using the RowDeleting and RowDeleted events for the GridView.
Currently when you build a command field for a delete button it will look something like this.
<asp:CommandFie ld ButtonType="Ima ge" DeleteImageUrl= "images/delete.gif" ShowDeleteButto n="true" />
By Changing the ButtonType to "Link" and modifying the DeleteText you will have the same delete image that works exactly like the Image Button Type but without the double firing event. Here is the modified code.
<asp:CommandFie ld ButtonType="Lin k" DeleteText="<im g src='images/delete.gif' alt='Delete this' border='0' />" ShowDeleteButto n="true" />
Additionally, I am constantly being asked about how to add a confirm dialog box to the delete button. You can use the following code on the RowDataBound event to add the confirmation.

If e.Row.RowType = DataControlRowT ype.DataRow Then
Dim lnk As LinkButton = e.Row.Cells(1). Controls(0)
lnk.OnClientCli ck = "if(!confirm('A re you sure you want to delete this?')) return false;"
End If
I hope this helps!
Jun 19 '07 #2
disa
1 New Member
http://bytes.com/topic/net/answers/6...d-firing-twice

Change the Button Field as Link Button:

Button field as Link button and, in the text, set de tag of a html image
<img src="IMAGENAME" >
and the event fires one time

<asp:ButtonFiel d Text="&lt;img src=Images/edit.gif /&gt;" HeaderText="Edi tar" >

</asp:ButtonField >
Jan 9 '09 #3

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

Similar topics

28
10255
by: Tim_Mac | last post by:
hi, i'm new to .net 2.0, and am just starting to get to grips with the gridview. my page has autoEventWireUp set to true, which i gather is supposed to figure out which handlers to invoke when appropriate based on your method names . the GridView has OnRowCommand="GridView1_RowCommand" in the aspx. my problem is that the RowCommand event is firing twice (95% of the time) on the page. the other 5% it only fires once. there's no
1
9103
by: Zule | last post by:
Hi, I am creating a Composite Control within which I have a GridView. In this GridView, I have three TemplateFields, the last one being a template with a LinkButton which is meant to be clicked so I can capture this event to do something about it. The problem is that in the CreateChildControls method, I initialize the GridView and link its RowCommand event to a method (so I can capture the LinkButton Click) but it doesn't work... I put...
3
8840
by: chelsea | last post by:
I am using a GridView control with a ButtonField and receiving 2 row command events for each click of the button. Is there a configuration switch that I can turn that will ensure I only receive one call to my handler? I'm using the most basic wiring as it comes out of VS 2005.. Thanks in advance for your help! ex/ <%@ Page Language="C#" AutoEventWireup="false" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
2
2181
by: luisxx | last post by:
WinSrv2003 SP1 IIS 6.0 ASP.NET C#, 2.0 SQL 2005 All on same machine Hello everyone! I have a method in ASP.NET 2.0 that I can't seem to get right, Gridview1_rowcommand.
4
6716
by: Chris Davoli | last post by:
I've got two questions on how to do things in the new GridView. I'm used to the DataGrid in ASP 1.1, so I need the equavalent in ASP 2.0 Gridview. 1.) What is the equavalent for Item Command event in GridView? I thought it would be RowCommand, but I can't get that event to fire with a check box field that I drag/drop in a template column in the ItemTemplate. 2.) For a Templated column, like a check box above, where do I tell it the...
6
28125
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the RowDataBound event to set the commandargument of the delete button. The event is being fired and works fine. When I press the delete button, the RowCommand event is not firing! and neither is the RowDeleting (the button's commandName is...
13
42002
by: AG | last post by:
I have a gridview that I bind to a List(of Type) at runtime. Not using a datasource control. The gridview has a template column with an imagebutton whose commandname is set to 'Delete'. The footer template has an commandbutton with the commandname set to 'Insert'. Both buttons cause postback, however the RowCommand event does not fire. How can I get the rowcommand to fire?
3
11711
by: AG | last post by:
Below is code (slightly modified and converted to VB) that was provided to me in response to another post. I am using it to demonstrate another problem. In order for paging and other features to work properly in a gridview, viewstate must be enabled. So, in order to minimize the size of viewstate for a page, I will sometimes turn off viewstate for each control in template columns. That means that the gridview must be databound on each...
7
17311
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi all! I have a gridview inside a datagrid (nested) for which (gridview) the rowcommand is not raised in order to delete a row from the grid! I also tried OnRowCommand="method", didn't work either! Does anyone know how can I make this work? Thanks in advance!
0
8174
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8618
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8568
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8257
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8423
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6083
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5537
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1699
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.