473,800 Members | 2,332 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="Defau lt2.aspx.cs"
Inherits="Defau lt2" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" DataSourceID="S qlDataSource1"
runat="server" OnRowCommand="A pprovalGrid_Row Command"
AutoGenerateCol umns="false" >
<Columns>
<asp:BoundFie ld DataField="Even tEmployeeId"
HeaderText="Emp loyee" ItemStyle-Width="80" />
<asp:BoundFie ld DataField="Even tTypeId" ItemStyle-Width="100"
HeaderText="Typ e"/>
<asp:ButtonFiel d buttontype="Ima ge"
ImageUrl="image s/icon-approve.gif" HeaderText="App rove" Text="Approve this
Event"
CommandName="Ap proveEvent" />
</Columns>
</asp:GridView>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:AttendanceMa nagement %>"
SelectCommand=" SELECT [EventId], [EventStartDate],
[EventEndDate], [EventDescriptio n], [EventTypeId], [EventHours],
[EventEmployeeId], [EventCreatorId], [EventCreationDa te],
[EventLastModifi erId], [EventLastModifi edDate], [EventApproved],
[EventApproverId], [EventApprovedDa te] FROM [Events]">
</asp:SqlDataSour ce>

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

-------------------------------------------------------------------------
using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

public partial class Default2 : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (!Page.IsPostBa ck)
{
}
}
protected void ApprovalGrid_Ro wCommand(object sender,
GridViewCommand EventArgs e)
{
// Get the index of the clicked row
int rowindex = Convert.ToInt32 (e.CommandArgum ent);

switch (e.CommandName)
{
case "ApproveEve nt":

break;
case "EditEvent" :

break;
}
}
}

--
chelsea
May 10 '06 #1
3 8852
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
3993
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 was endeavoring to create a custom user control to make things a bit simpler, but she noticed that her Page_Load eventhandler was firing twice. So after long hours of research and experimentation, I stumbled upon, imho, is quite the discovery. ...
28
10281
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
13
42073
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?
14
8686
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 made when upgrading to 2.0 is there any reason for this because of .net 2.0? thanks
2
11041
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 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.
0
1287
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
2871
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 that button, but everytime the button is clicked, the page posts back and the click event does not fire (probably because the button gets created every single time there's a postback). What is the best way for me to create
3
2532
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 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...
1
5834
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" AllowPaging="True" > <PagerTemplate> <% if (gridView.PageIndex > 0) { %> <asp:ImageButton ID="imgBtnPrevious" runat="server"
0
9691
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
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
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...
1
10253
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
10035
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...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7580
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
6813
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();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.