473,395 Members | 1,471 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,395 software developers and data experts.

Row Command Firing twice in GridView Control


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" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" DataSourceID="SqlDataSource1"
runat="server" OnRowCommand="ApprovalGrid_RowCommand"
AutoGenerateColumns="false" >
<Columns>
<asp:BoundField DataField="EventEmployeeId"
HeaderText="Employee" ItemStyle-Width="80" />
<asp:BoundField DataField="EventTypeId" ItemStyle-Width="100"
HeaderText="Type"/>
<asp:ButtonField buttontype="Image"
ImageUrl="images/icon-approve.gif" HeaderText="Approve" Text="Approve this
Event"
CommandName="ApproveEvent" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AttendanceManagement %>"
SelectCommand="SELECT [EventId], [EventStartDate],
[EventEndDate], [EventDescription], [EventTypeId], [EventHours],
[EventEmployeeId], [EventCreatorId], [EventCreationDate],
[EventLastModifierId], [EventLastModifiedDate], [EventApproved],
[EventApproverId], [EventApprovedDate] FROM [Events]">
</asp:SqlDataSource>

</div>
</form>
</body>
</html>

-------------------------------------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
}
protected void ApprovalGrid_RowCommand(object sender,
GridViewCommandEventArgs e)
{
// Get the index of the clicked row
int rowindex = Convert.ToInt32(e.CommandArgument);

switch (e.CommandName)
{
case "ApproveEvent":

break;
case "EditEvent":

break;
}
}
}

--
chelsea
May 10 '06 #1
3 8817
Hi Chelsea,

Thank you for posting.

From your description, on one of your ASP.NET 2.0 web page which contains a
Gridview control, the GridView control's Rowcommand event handler will be
called twice each time it is postback, correct?

As for such event handler executing twice problem, I've also encountered
some formerly and there may exists different causes on this. First, I'd
like to make sure whether this is a page/application or machine specific
issue. To isolate the issue, you can creating other simple test page with
GridView to test or event test the same page on different machines to
verify the behavior.

Also, in addition to the Gridview's RowCommand, does any other events of
the Gridview control (like load..) or event the Page's event like Init,
Load fires twice each time the page post back. Such behavior will also
provide some clues on the problem.

If there's any other finding, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 10 '06 #2
Steven- Thank you so much for the attention to this issue. The problem does
happen on both my development workstation and the deployment server. It
seems to be a bit intermittent in that sometimes a click of the button will
only fire the rowcommand once, but other times it fires twice. The sequence
of events that I observe when the problem happens is:

1.) Page_Load Event fires
2.) -- Grid is displayed and I click the button
3.) Page_Load Post Back fires
4.) Page_Load Post Back fires
5.) Row Command fires
6.) Row Command fires

I'm capturing this activity by setting breaks in the code under VS 2005.
Also, the above results were received when AutoEventWireup="true". My
original post showed wireup="false". Thanks again for your help.

--
chelsea
"Steven Cheng[MSFT]" wrote:
Hi Chelsea,

Thank you for posting.

From your description, on one of your ASP.NET 2.0 web page which contains a
Gridview control, the GridView control's Rowcommand event handler will be
called twice each time it is postback, correct?

As for such event handler executing twice problem, I've also encountered
some formerly and there may exists different causes on this. First, I'd
like to make sure whether this is a page/application or machine specific
issue. To isolate the issue, you can creating other simple test page with
GridView to test or event test the same page on different machines to
verify the behavior.

Also, in addition to the Gridview's RowCommand, does any other events of
the Gridview control (like load..) or event the Page's event like Init,
Load fires twice each time the page post back. Such behavior will also
provide some clues on the problem.

If there's any other finding, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 10 '06 #3
Hi Chelsea,

Thank you for your posting.

It seems that when the page postback, even the page level load (or init?)
event handler will be executed twice. I'm wondering whether there has come
two postback requests to the page. You can check the IIS log to see whether
there exists two requests from client when the page is postback.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Seraph | last post by:
Again, I'm rather new here, so if I fail to follow any etiquette, please forgive me and let me know what I've done wrong, but I think this might interest quite a few people. One of my colleaques...
28
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...
13
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...
14
by: TS | last post by:
I have this custom data list control and i override the onItemDatabound event. After upgrading to vs 2005, this event is not always getting called, though it does at other times. No changes were...
2
by: John007 | last post by:
I am using a GridView in ASP.Net 2.0 to Insert, Edit, Update and Delete. I am using ItemTemplate and EditItemTemplate and the buttons are LinkButtons. I am inserting a new row from the footer. The...
0
by: Ganesh | last post by:
gridview row command event is not firing in Mozilla , asp.net 2.0 need to select a row and store the hidden value of that prticlar row in session working fine in IE
1
by: ADN | last post by:
Hi, I am currently extending the GridView control and would like to add a button to the GridView so that it will automatically render one button at the top of the grid. I have a click event for...
3
by: myth0s | last post by:
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...
1
by: pupilstuff | last post by:
hi guys rowcommand event id not firing my code is <asp:GridView ID="gridView" runat="server" Style="position: relative" PageSize="5" OnRowCommand="gridView_OnRowCommand" ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.