By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 1,647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

help please on GridView commands + AutoEventWireUp, firing twice etc...

P: n/a
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
consistency at all.

in .net 1.1, i would have understood that the code-behind was wiring up
the event, and the aspx was doing the same thing, so this would result
in the event being raised twice. however, in .net 2, i can't find any
code-behind that would be doing this (even looked in temp.asp.net
files).

if i set autoEventWireUp=true, with the OnRowCommand declared in the
GridView aspx, Page_Load fires twice, so does GridView1_RowCommand.

if i set AutoEventWireup=false, PageLoad doesn't fire (as is expected)
and GridView1_RowCommand only fires once. but occassionally it fires
twice. this is painful! somebody please put me out of my misery :-)

here is my code:
******** ASPX *********
<%@ Page Language="C#" AutoEventWireup="false"
CodeFile="TestGridView.aspx.cs" Inherits="Admin_TestGridView" %>

<!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">
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="PageID"
DataSourceID="dsPages"
OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="TitleForEdit"
HeaderText="Title" />
<asp:ButtonField ButtonType="Image"
CommandName="MoveUp" ImageUrl="../Images/Move_Up.gif"
Text="Move this page up one position" />
<asp:ButtonField ButtonType="Image"
CommandName="MoveDown" ImageUrl="../Images/Move_Down.gif"
Text="Move this page down one position" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="dsPages" runat="server"
SelectMethod="Select" TypeName="PageManager">
</asp:ObjectDataSource>
</form>
</body>
</html>
********** CODE BEHIND ***********
public partial class Admin_TestGridView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Page_Load<HR>");
}

protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
Response.Write("GridView1_RowCommand<HR>");
}
}

what i did was put break-points in both events, debug, and keep
clicking the up/down buttons until you see the event hit twice for one
click.

thank you
tim

Dec 16 '05 #1
Share this Question
Share on Google+
28 Replies


P: n/a
Hi tim,

You do not need to specify the OnRowCommand if you have the autoEventWireUp
=true.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Tim_Mac" wrote:
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
consistency at all.

in .net 1.1, i would have understood that the code-behind was wiring up
the event, and the aspx was doing the same thing, so this would result
in the event being raised twice. however, in .net 2, i can't find any
code-behind that would be doing this (even looked in temp.asp.net
files).

if i set autoEventWireUp=true, with the OnRowCommand declared in the
GridView aspx, Page_Load fires twice, so does GridView1_RowCommand.

if i set AutoEventWireup=false, PageLoad doesn't fire (as is expected)
and GridView1_RowCommand only fires once. but occassionally it fires
twice. this is painful! somebody please put me out of my misery :-)

here is my code:
******** ASPX *********
<%@ Page Language="C#" AutoEventWireup="false"
CodeFile="TestGridView.aspx.cs" Inherits="Admin_TestGridView" %>

<!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">
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="PageID"
DataSourceID="dsPages"
OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="TitleForEdit"
HeaderText="Title" />
<asp:ButtonField ButtonType="Image"
CommandName="MoveUp" ImageUrl="../Images/Move_Up.gif"
Text="Move this page up one position" />
<asp:ButtonField ButtonType="Image"
CommandName="MoveDown" ImageUrl="../Images/Move_Down.gif"
Text="Move this page down one position" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="dsPages" runat="server"
SelectMethod="Select" TypeName="PageManager">
</asp:ObjectDataSource>
</form>
</body>
</html>
********** CODE BEHIND ***********
public partial class Admin_TestGridView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Page_Load<HR>");
}

protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
Response.Write("GridView1_RowCommand<HR>");
}
}

what i did was put break-points in both events, debug, and keep
clicking the up/down buttons until you see the event hit twice for one
click.

thank you
tim

Dec 16 '05 #2

P: n/a
hi Philip, thanks for the reply.
ok so that is what's supposed to happen, i would agree with you.
except... when i set autoEventWireUp=true, the GridView1_RowCommand
event is not raised at all when i click one of the button fields, and
Page_Load fires twice when i click the button. it only fires once when
the page is first loaded.

the code i'm using is the exact same as posted above, except
OnRowCommand has been removed from the gridView aspx, and
autoEventWireUp has been changed to true.

why would Page_Load fire twice, and why does autoEventWireUp not do
it's job in hooking up my RowCommand event handler?

thanks
tim

Dec 18 '05 #3

P: n/a
Hi Tim,

Thanks for responding. This discussion got me to correct some of my
misconceptions about the AutoEventWireUp property.

Here is what I found by researching the topic:
1- The AutoEventWireUp applies only to the page events. For an explanation
of the page events:
http://msdn2.microsoft.com/en-us/lib...US,VS.80).aspx
2- You have to wire up the events for the controls within the page even if
you have the AutoEventWireUp=true. The VS.Net does that automatically when
you double click on a control by adding markup for you within the server
control.

To verify my findings, I created 3 demos out of the code that you posted
earlier:
1- In this demo the AutoEventWireUp is set to true and the event fire up
twice because I have also overridden the OnInit method and put event wiring
for controls in it
http://www.webswapp.com/CodeSamples/...rue_Error.aspx

2- In this demo the AutoEventWireUp is set to true and everything works as
expected
http://www.webswapp.com/CodeSamples/...reUp_True.aspx

3- In this demo the AutoEventWireUp is set to false (my preference in
programming because it improves performance) and everything works as expected
http://www.webswapp.com/CodeSamples/...eUp_False.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Tim_Mac" wrote:
hi Philip, thanks for the reply.
ok so that is what's supposed to happen, i would agree with you.
except... when i set autoEventWireUp=true, the GridView1_RowCommand
event is not raised at all when i click one of the button fields, and
Page_Load fires twice when i click the button. it only fires once when
the page is first loaded.

the code i'm using is the exact same as posted above, except
OnRowCommand has been removed from the gridView aspx, and
autoEventWireUp has been changed to true.

why would Page_Load fire twice, and why does autoEventWireUp not do
it's job in hooking up my RowCommand event handler?

thanks
tim

Dec 19 '05 #4

P: n/a
Hi Tim,

As for ASP.NET 2.0's new page compilation model, the AutoWireupEvent is no
longer turn off by default in VS2005 web project IDE. And the page's
AutoEventWireup should only apply to page's events rather than any other
server controls' events. So if we have the page's AutoEventWireup set to
"false" and we don't explicitly register Page_load function for page, and
also dosn't add GridView's RowCommand event handler in the aspx template,
neither event handler should be fired.....

so for your scenario, I think it should be an page specific or environment
specific problem. Here is test page I used on myside which works as
expected:(I also use the page's OutputTrace to print the event handler
exection time.....)

#when AutoWireupEvent turn off, Page_Load not executed , but RowCommand
still work since it is delcared through aspx template's control attribute

#when AutoWireupEvent turn on, both event handler get executed and only
once.....

You can have a test through it to see whether it also encounter the problem:

=========aspx==========
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="EventWireupPage.aspx.cs" Inherits="EventWireupPage" Trace="true"
%>

<!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:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:LocalNorthWind %>"
SelectCommand="SELECT [CategoryID], [CategoryName],
[Description] FROM [Categories]">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="CategoryID"
DataSourceID="SqlDataSource1"
OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="CategoryID"
HeaderText="CategoryID" InsertVisible="False"
ReadOnly="True" SortExpression="CategoryID" />
<asp:BoundField DataField="CategoryName"
HeaderText="CategoryName" SortExpression="CategoryName" />
<asp:BoundField DataField="Description"
HeaderText="Description" SortExpression="Description" />
<asp:ButtonField CommandName="MoveUp" Text="MoveUp" />
<asp:ButtonField CommandName="MoveDown" Text="MoveDown" />
</Columns>
</asp:GridView>

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

==========code behind==========
public partial class EventWireupPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Trace.Write("Page_load " + DateTime.Now.ToLongTimeString() );
}
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
Trace.Write("RowCommand " + e.CommandName + " " +
DateTime.Now.ToLongTimeString());
}
}
====================

Please feel free to post here when you have any furhter finding or need any
assistance.

Regards,

Steven Cheng
Microsoft Online Support

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

--------------------
| Thread-Topic: help please on GridView commands + AutoEventWireUp, firing
twi
| thread-index: AcYEVW+3hSkc5a7PT+ar2/nTIb7cww==
| X-WBNR-Posting-Host: 70.68.38.48
| From: "=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?="
<Ph**************@webswapp.com>
| References: <11**********************@z14g2000cwz.googlegroups .com>
<B6**********************************@microsoft.co m>
<11**********************@g44g2000cwa.googlegroups .com>
| Subject: Re: help please on GridView commands + AutoEventWireUp, firing
twi
| Date: Sun, 18 Dec 2005 20:34:02 -0800
| Lines: 56
| Message-ID: <D9**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:365626
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi Tim,
|
| Thanks for responding. This discussion got me to correct some of my
| misconceptions about the AutoEventWireUp property.
|
| Here is what I found by researching the topic:
| 1- The AutoEventWireUp applies only to the page events. For an
explanation
| of the page events:
| http://msdn2.microsoft.com/en-us/lib...US,VS.80).aspx
| 2- You have to wire up the events for the controls within the page even
if
| you have the AutoEventWireUp=true. The VS.Net does that automatically
when
| you double click on a control by adding markup for you within the server
| control.
|
| To verify my findings, I created 3 demos out of the code that you posted
| earlier:
| 1- In this demo the AutoEventWireUp is set to true and the event fire up
| twice because I have also overridden the OnInit method and put event
wiring
| for controls in it
|
http://www.webswapp.com/CodeSamples/...rue_Error.aspx
|
| 2- In this demo the AutoEventWireUp is set to true and everything works
as
| expected
| http://www.webswapp.com/CodeSamples/...reUp_True.aspx
|
| 3- In this demo the AutoEventWireUp is set to false (my preference in
| programming because it improves performance) and everything works as
expected
| http://www.webswapp.com/CodeSamples/...eUp_False.aspx
|
| --
| HTH,
| Phillip Williams
| http://www.societopia.net
| http://www.webswapp.com
|
|
| "Tim_Mac" wrote:
|
| > hi Philip, thanks for the reply.
| > ok so that is what's supposed to happen, i would agree with you.
| > except... when i set autoEventWireUp=true, the GridView1_RowCommand
| > event is not raised at all when i click one of the button fields, and
| > Page_Load fires twice when i click the button. it only fires once when
| > the page is first loaded.
| >
| > the code i'm using is the exact same as posted above, except
| > OnRowCommand has been removed from the gridView aspx, and
| > autoEventWireUp has been changed to true.
| >
| > why would Page_Load fire twice, and why does autoEventWireUp not do
| > it's job in hooking up my RowCommand event handler?
| >
| > thanks
| > tim
| >
| >
|

Dec 19 '05 #5

P: n/a
philip, many thanks for the examples.
steven, thanks also for the reply. i have narrowed down my problem,
and i am quite sure at this stage that i have encountered a bizarre
behaviour/bug/feature/whatever.

if you take your sample page that you made, and add the following
attributes to the 2 button fields:
ButtonType="image" ImageUrl="MoveUp.gif"

if you debug your code then, you will see Page_Load gets invoked twice,
and so does RowCommand. that's the only change i made, and when i go
back to your original version with the text/button columns, it works
fine. this is an empty web project with one aspx page so there are no
unusual config problems.

it is very frustrating!! i hope you can shed some light on this
behaviour.
thanks
tim

Dec 19 '05 #6

P: n/a
Hey Tim,

Thanks for your quick response.
I've just made some further test according to the change you mentioened,
below is my modiied page's aspx template:

However, I still only get the Page_Load or GridView_OnRowCommand fire
once.... Would you please attache a complete project that contains such a
reproduce page in it so that I can test through the complete project on
myside?
========aspx==========
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="EventWireupPage.aspx.cs" Inherits="EventWireupPage" Trace="false"
%>

<!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:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:LocalNorthWind %>"
SelectCommand="SELECT [CategoryID], [CategoryName],
[Description] FROM [Categories]">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="CategoryID"
DataSourceID="SqlDataSource1"
OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="CategoryID"
HeaderText="CategoryID" InsertVisible="False"
ReadOnly="True" SortExpression="CategoryID" />
<asp:BoundField DataField="CategoryName"
HeaderText="CategoryName" SortExpression="CategoryName" />
<asp:BoundField DataField="Description"
HeaderText="Description" SortExpression="Description" />
<asp:ButtonField CommandName="MoveUp" ButtonType=image
ImageUrl="~/Images/menu_pop_dynamic.GIF" Text="MoveUp" />
<asp:ButtonField CommandName="MoveDown" ButtonType=image
ImageUrl="~/Images/menu_pop_static.GIF" Text="MoveDown" />
</Columns>
</asp:GridView>

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

Thanks,

Steven Cheng
Microsoft Online Support

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

--------------------
| From: "Tim_Mac" <ti*@mackey.ie>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Subject: Re: help please on GridView commands + AutoEventWireUp, firing
twi
| Date: 19 Dec 2005 03:56:12 -0800
| Organization: http://groups.google.com
| Lines: 20
| Message-ID: <11**********************@f14g2000cwb.googlegroups .com>
| References: <11**********************@z14g2000cwz.googlegroups .com>
| <B6**********************************@microsoft.co m>
| <11**********************@g44g2000cwa.googlegroups .com>
| <D9**********************************@microsoft.co m>
| <Zp**************@TK2MSFTNGXA02.phx.gbl>
| NNTP-Posting-Host: 83.141.121.205
| Mime-Version: 1.0
| Content-Type: text/plain; charset="iso-8859-1"
| X-Trace: posting.google.com 1134993378 19451 127.0.0.1 (19 Dec 2005
11:56:18 GMT)
| X-Complaints-To: gr**********@google.com
| NNTP-Posting-Date: Mon, 19 Dec 2005 11:56:18 +0000 (UTC)
| In-Reply-To: <Zp**************@TK2MSFTNGXA02.phx.gbl>
| User-Agent: G2/0.2
| X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8)
Gecko/20051111 Firefox/1.5,gzip(gfe),gzip(gfe)
| Complaints-To: gr**********@google.com
| Injection-Info: f14g2000cwb.googlegroups.com; posting-host=83.141.121.205;
| posting-account=UaxKfw0AAAA4oMLJHydK195yIv1avAma
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli
ne.de!news.glorb.com!postnews.google.com!f14g2000c wb.googlegroups.com!not-fo
r-mail
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:365670
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| philip, many thanks for the examples.
| steven, thanks also for the reply. i have narrowed down my problem,
| and i am quite sure at this stage that i have encountered a bizarre
| behaviour/bug/feature/whatever.
|
| if you take your sample page that you made, and add the following
| attributes to the 2 button fields:
| ButtonType="image" ImageUrl="MoveUp.gif"
|
| if you debug your code then, you will see Page_Load gets invoked twice,
| and so does RowCommand. that's the only change i made, and when i go
| back to your original version with the text/button columns, it works
| fine. this is an empty web project with one aspx page so there are no
| unusual config problems.
|
| it is very frustrating!! i hope you can shed some light on this
| behaviour.
| thanks
| tim
|
|

Dec 20 '05 #7

P: n/a
hi Steven,
i sent the solution to your newsgroup email address without the
'online'. hope it gets through.
thanks
tim

Dec 20 '05 #8

P: n/a
Hi Tim,

I have tested the project you sent me, however, it seems that I still get
the Page_Load and GridView's OnRowCommand event handler fired once (page's
AutoWireupEvent turn on). Have you checked the IIS log when you performing
the gridView's postback command to see whether there're any other log
entries mapped to that page?
Also, if possible, you can also try the same page on some other machine or
create a new project to perform the same test...

Thanks,

Steven Cheng
Microsoft Online Support

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

--------------------
| From: "Tim_Mac" <ti*@mackey.ie>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Subject: Re: help please on GridView commands + AutoEventWireUp, firing
twi
| Date: 20 Dec 2005 05:03:45 -0800
| Organization: http://groups.google.com
| Lines: 6
| Message-ID: <11*********************@z14g2000cwz.googlegroups. com>
| References: <11**********************@z14g2000cwz.googlegroups .com>
| <11**********************@f14g2000cwb.googlegroups .com>
| <18**************@TK2MSFTNGXA02.phx.gbl>
| NNTP-Posting-Host: 83.141.121.205
| Mime-Version: 1.0
| Content-Type: text/plain; charset="iso-8859-1"
| X-Trace: posting.google.com 1135083830 5044 127.0.0.1 (20 Dec 2005
13:03:50 GMT)
| X-Complaints-To: gr**********@google.com
| NNTP-Posting-Date: Tue, 20 Dec 2005 13:03:50 +0000 (UTC)
| In-Reply-To: <18**************@TK2MSFTNGXA02.phx.gbl>
| User-Agent: G2/0.2
| X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8)
Gecko/20051111 Firefox/1.5,gzip(gfe),gzip(gfe)
| Complaints-To: gr**********@google.com
| Injection-Info: z14g2000cwz.googlegroups.com; posting-host=83.141.121.205;
| posting-account=UaxKfw0AAAA4oMLJHydK195yIv1avAma
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli
ne.de!border2.nntp.dca.giganews.com!border1.nntp.d ca.giganews.com!nntp.gigan
ews.com!postnews.google.com!z14g2000cwz.googlegrou ps.com!not-for-mail
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:365929
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| hi Steven,
| i sent the solution to your newsgroup email address without the
| 'online'. hope it gets through.
| thanks
| tim
|
|

Dec 21 '05 #9

P: n/a
hi Steven,
thanks for continuing to look into it. i have just tried it on my
production server, windows 2003 enterrprise, asp.net 2. and i get the
same behaviour, double events for postback.
i found the system log to be a reliable way to record the behaviour of
each event execution. this rules out any debugger anomalies etc.

the output from the IIS log shows the double requests. the log
activity consists of one access to the page, followed by a click on the
move-down button, which as you can see triggers two POST events at the
same time, both with IIS status 200.

#Fields: date time cs-method cs-uri-stem cs-uri-query s-port
cs-username c-ip cs-version cs(User-Agent) sc-status sc-substatus
sc-win32-status sc-bytes
2005-12-21 14:58:57 GET /EventWireupPage.aspx - 8090 - xx.yyy.zzz.zzz
HTTP/1.1
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2;+SV1;+.N ET+CLR+1.1.4322;+.NET+CLR+2.0.50727)
200 0 0 35998
2005-12-21 14:58:57 GET /MoveDown.gif - 8090 - xx.yyy.zzz.zzz HTTP/1.1
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2;+SV1;+.N ET+CLR+1.1.4322;+.NET+CLR+2.0.50727)
404 0 2 1795
2005-12-21 14:59:00 POST /EventWireupPage.aspx - 8090 - xx.yyy.zzz.zzz
HTTP/1.1
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2;+SV1;+.N ET+CLR+1.1.4322;+.NET+CLR+2.0.50727)
200 0 64 0
2005-12-21 14:59:00 POST /EventWireupPage.aspx - 8090 - xx.yyy.zzz.zzz
HTTP/1.1
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2;+SV1;+.N ET+CLR+1.1.4322;+.NET+CLR+2.0.50727)
200 0 0 39927
2005-12-21 14:59:00 GET /MoveDown.gif - 8090 - xx.yyy.zzz.zzz HTTP/1.1
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2;+SV1;+.N ET+CLR+1.1.4322;+.NET+CLR+2.0.50727)
404 0 2 1795

my updated code is below, i didn't make any other changes:
public partial class EventWireupPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Diagnostics.EventLog.WriteEntry("ASPNET", "Page_Load");
}

protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
System.Diagnostics.EventLog.WriteEntry("ASPNET",
"GridView1_RowCommand");
}
}

by the way, the only way i noticed it was because of a swap routine
with the move up/down buttons, which obviously when you execute the
same swap twice, it does not change the ordering of the items. if you
use tracing it only shows the trace for one of the postbacks, and
similarly response.Write does not help, so the event log is a sure way
to track it. the event log shows an event for Page_Load corresponding
to the first page access, then there are 2 Page_Load events and 2
RowCommand events, corresponding to the postback(s).

i'm grateful for any more clues you may have to try and get to the
bottom of this.
thanks
tim

Dec 21 '05 #10

P: n/a
just to add to the melting pot, i noticed the "sc-win32-status" value
is 64 for the first bogus postback, i say the first one is bogus
because it has 0 bytes size. but it definitely executes on the server.
i did some hunting around on google for sc-win32-status 64, and i found
many unresolved posts of people reporting problems, some relating to
postback, with this type of log entry.

http://groups.google.com/groups?q=sc...64&qt_s=Search

Dec 21 '05 #11

P: n/a
Thanks for your response Tim,

It sounds very strange that there occurs two requests each time (since the
IIS log shows two POST entries each time....), I've also discussed with
our IIS engineer, I think we may need to use some http or TCP trace tool to
capture the two requests... Is the "two request" behavior always occuring
both when we request the page from local server or from a remote client
machine?

There're some http/tcp trace tools like the Trace Utility in soap toolkit
or tcptrace....:

SOAP TOOLKIT 3.0
http://www.microsoft.com/downloads/d...0DD-CEEC-4088-
9753-86F052EC8450&displaylang=en

tcptrace
http://www.pocketsoap.com/tcptrace/

Also, if you have any other trace tools which can catpure http request,
that'll be ok. We need to capture the http message's content to see what's
the difference between them. Also, if the problem also occur on other
remote client, we can also confirm whether the two request are caused by
client browser or serverside....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Tim_Mac" <ti*@mackey.ie>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Subject: Re: help please on GridView commands + AutoEventWireUp, firing
twi
| Date: 21 Dec 2005 09:09:18 -0800
| Organization: http://groups.google.com
| Lines: 9
| Message-ID: <11**********************@z14g2000cwz.googlegroups .com>
| References: <11**********************@z14g2000cwz.googlegroups .com>
| <11*********************@z14g2000cwz.googlegroups. com>
| <Yh**************@TK2MSFTNGXA02.phx.gbl>
| <11**********************@g49g2000cwa.googlegroups .com>
| NNTP-Posting-Host: 83.141.121.205
| Mime-Version: 1.0
| Content-Type: text/plain; charset="iso-8859-1"
| X-Trace: posting.google.com 1135184963 5422 127.0.0.1 (21 Dec 2005
17:09:23 GMT)
| X-Complaints-To: gr**********@google.com
| NNTP-Posting-Date: Wed, 21 Dec 2005 17:09:23 +0000 (UTC)
| In-Reply-To: <11**********************@g49g2000cwa.googlegroups .com>
| User-Agent: G2/0.2
| X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8)
Gecko/20051111 Firefox/1.5,gzip(gfe),gzip(gfe)
| Complaints-To: gr**********@google.com
| Injection-Info: z14g2000cwz.googlegroups.com; posting-host=83.141.121.205;
| posting-account=UaxKfw0AAAA4oMLJHydK195yIv1avAma
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli
ne.de!border2.nntp.dca.giganews.com!border1.nntp.d ca.giganews.com!nntp.gigan
ews.com!postnews.google.com!z14g2000cwz.googlegrou ps.com!not-for-mail
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:366303
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| just to add to the melting pot, i noticed the "sc-win32-status" value
| is 64 for the first bogus postback, i say the first one is bogus
| because it has 0 bytes size. but it definitely executes on the server.
| i did some hunting around on google for sc-win32-status 64, and i found
| many unresolved posts of people reporting problems, some relating to
| postback, with this type of log entry.
|
| http://groups.google.com/groups?q=sc...64&qt_s=Search
|
|

Dec 23 '05 #12

P: n/a
hi Steven,
thanks for the reply. yes it does happen while browsing remotely or
locally. but i can only reproduce the double-postback in IE6. it
never happens in IE5.0 (tested on windows 2000) or FireFox 1.5. my IE
and FF testing is on a fully up-to-date XP pro sp2.

i set up TcpTrace, and recorded 2 different log files, one while
browsing with IE6, and the other with FF. you can download them here:
http://tim.mackey.ie/stuff/IE_dud_postback.xml
http://tim.mackey.ie/stuff/FF_OK_PostBack.xml

The first file "IE_Dud_postback" shows 5 connections, i will summarise
below:
+ GET aspx page
+ GET the image
+ POST aspx page, note that bytes are sent but no bytes are received
back by the client
+ POST aspx page, this is the second postback, which gets a response
from the server.
+ GET the image

from debugging and event logging etc, i am 100% certain that .Net
executes Page_Load and GridView_RowCommand for both of those postbacks.
i'm using the same code as i posted previously.

the firefox sequence of events is as expected, only one postback. this
only seems to happen on ButtonField's with ButtonType="Image"

is there any more information i can provide? if i found a really big
bug do i get a prize? :)

tim

Jan 4 '06 #13

P: n/a
Hi all,

Just to let you know, Tim, that YOU ARE NOT ALONE!!! We've been
developping Web applications with .NET 2.0 and are struggling with the
same undocumented features.

The workaround we are using is based on the fact that the correct
request includes the same POST-data of the first request together with
extra values. These values are coordinates of the click on the image of
the ButtonField, if you are using the ButtonType set to Image, ofcourse.

<asp:ButtonField ButtonType="Image" ... />

To detect the second / good post, you can simply check the presence of
the Request-variables "x" and "y":

if(this.Request["x"]==null || this.Request["y"]==null)
{ // This is fake }

These variables should contain integer-positions of the click on the
image and this is the behavior in FireFox, Opera and Internet Explorer.
We didn't test on other clients nor systems, though.

Any decent way to avoid this problem is welcome!

I hope this can help you and I hope Steven can give us an official tip!

Wim
*** Sent via Developersdex http://www.developersdex.com ***
Jan 11 '06 #14

P: n/a
hi wim, what a great work-around!!
thank you so much for posting this. hopefully Steven will be back from
newsgroup holidays soon :)

Jan 11 '06 #15

P: n/a
just to add to my previous post, the code wim posted should only be
included for ButtonFields with type="image". so don't put it in your
Page_Load or it will interfere with normal postbacks for other buttons
on the page etc.
as well as this, make sure you don't use the code with a LinkButton
inside a TemplateField, as it may kill the correct postback.

a sample of the scenario where i use the work-around code is as
follows:

protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
switch (e.CommandName)
{
case "MoveUp":
// check for bogus postback from ImageButton
if(this.Request["x"] == null && this.Request["y"] == null)
Response.End();
....

Jan 13 '06 #16

P: n/a
Hi all, i have the same problem
I note that the first request is 8 byte less than the second. I think
they are X=... and Y=...

I appreciates the solution if(...=null..&& ..=null)
but i think it's not possible. If it's a bug microsoft have to solve!
Ema

*** Sent via Developersdex http://www.developersdex.com ***
Feb 1 '06 #17

P: n/a
Ema,

Yes, the request is at least 8 bytes longer, depending on the image
coordinates. The querystring for small coordinates (lower then 10) is
for example: &x=5&y=7. This means an increase of 8 bytes. If the
coordinates are heigher, this will result in more bytes, eg. &x=14&y=30
is a total of 10 bytes.

The quick-hack work-around unprofessional solution is not acceptable,
but we are waiting for any comments from Microsoft! Go Bill, go Bill!

Greetings,
Wim Verbeke
*** Sent via Developersdex http://www.developersdex.com ***
Feb 1 '06 #18

P: n/a
Hi,
1.I'm looking also gridview_rowEditing and i have the same problem. I
have not it on RowDeleting (i don't know why)

Have someone understood when it happens (for me it is random!)??

2.If it's related with imagebutton why I haven't using only imagebutton
without gridview?

Ema

*** Sent via Developersdex http://www.developersdex.com ***
Feb 3 '06 #19

P: n/a
I would tell you that the previous solution is not good if i'm
implementing moveup/down,edit and cancel(all imagebutton with
commandname).
It seems code executes Rowcommand and then RowEditing/RowDeleting. If
you use that code, then delete doesn't work properly (i add to my button
javascript to confirm). So i use:

if (Request["x"] == null && Request["y"] == null && (e.CommandName ==
"MoveUp" || e.CommandName == "MoveDown"))
Response.End();

In RowEditing i use:
if (Request["x"] == null && Request["y"] == null)
Response.End();
Ema

*** Sent via Developersdex http://www.developersdex.com ***
Feb 3 '06 #20

P: n/a
up to attention...

Ema

*** Sent via Developersdex http://www.developersdex.com ***
Feb 8 '06 #21

P: n/a
noone answer to this threaD?

Ema

*** Sent via Developersdex http://www.developersdex.com ***
Feb 15 '06 #22

P: n/a
i've reposted the problem due to lack of response on this thread. i
am awaiting a reply from an MS guy. the new thread is at
http://groups.google.com/group/micro...2e4efa2d10e573

Feb 15 '06 #23

P: n/a
Does anyone have an update on this issue? I'm running into the same
thing. Random multiple POSTs causing duplicate charges/credits for
clients. Subsequent POSTs are sent when the first POST receives a 200 0
64 response. Users swear they did not click the Submit button twice.

*** Sent via Developersdex http://www.developersdex.com ***
Feb 23 '06 #24

P: n/a
This bug has been forwarded to Microsoft.
This is the answer from Microsoft Bug adn reported issues:

Thanks for reporting the issue. This is a known issue and we are
investigating fixing this in the next service pack. For the time being
you could use the following work around. One obvious workaround is to
change the button type to a regular button or a link button. If you need
an ImageButton, then you can put an ImageButton in a TemplateField. You
may need to handle the Command event on the ImageButton and call
DeleteRow, passing the RowIndex as the CommandArgument, like this:

<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton runat=server id="ImageButton1" CommandName="Delete"
ImageUrl="..." CommandArgument='<%# DataBinder.Eval(Container,
"RowIndex") %>' OnCommand="ImageButton1_Command" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

protected void ImageButton1_Command(object sender, CommandEventArgs e) {
GridView1.DeleteRow(Int32.Parse(e.CommandArgument. ToString()));
}

Thanks,
The Web Platform and Tools Team
You can find discussion in the site in the previous post or to
http://forum.aspitalia.com/forum/pos...agebutton.aspx
Ema

*** Sent via Developersdex http://www.developersdex.com ***
Feb 24 '06 #25

P: 1
I ran into the exact same problem, and for some reason, setting the CausesValidation="True" to the buttonfield (which b.t.w. is ButtonType="Image") solved it.


hi Steven,
thanks for continuing to look into it. i have just tried it on my
production server, windows 2003 enterrprise, asp.net 2. and i get the
same behaviour, double events for postback.
i found the system log to be a reliable way to record the behaviour of
each event execution. this rules out any debugger anomalies etc.

the output from the IIS log shows the double requests. the log
activity consists of one access to the page, followed by a click on the
move-down button, which as you can see triggers two POST events at the
same time, both with IIS status 200.

#Fields: date time cs-method cs-uri-stem cs-uri-query s-port
cs-username c-ip cs-version cs(User-Agent) sc-status sc-substatus
sc-win32-status sc-bytes
2005-12-21 14:58:57 GET /EventWireupPage.aspx - 8090 - xx.yyy.zzz.zzz
HTTP/1.1
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2;+SV1;+.N ET+CLR+1.1.4322;+.NET+CLR+2.0.50727)
200 0 0 35998
2005-12-21 14:58:57 GET /MoveDown.gif - 8090 - xx.yyy.zzz.zzz HTTP/1.1
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2;+SV1;+.N ET+CLR+1.1.4322;+.NET+CLR+2.0.50727)
404 0 2 1795
2005-12-21 14:59:00 POST /EventWireupPage.aspx - 8090 - xx.yyy.zzz.zzz
HTTP/1.1
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2;+SV1;+.N ET+CLR+1.1.4322;+.NET+CLR+2.0.50727)
200 0 64 0
2005-12-21 14:59:00 POST /EventWireupPage.aspx - 8090 - xx.yyy.zzz.zzz
HTTP/1.1
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2;+SV1;+.N ET+CLR+1.1.4322;+.NET+CLR+2.0.50727)
200 0 0 39927
2005-12-21 14:59:00 GET /MoveDown.gif - 8090 - xx.yyy.zzz.zzz HTTP/1.1
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2;+SV1;+.N ET+CLR+1.1.4322;+.NET+CLR+2.0.50727)
404 0 2 1795

my updated code is below, i didn't make any other changes:
public partial class EventWireupPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Diagnostics.EventLog.WriteEntry("ASPNET", "Page_Load");
}

protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
System.Diagnostics.EventLog.WriteEntry("ASPNET",
"GridView1_RowCommand");
}
}

by the way, the only way i noticed it was because of a swap routine
with the move up/down buttons, which obviously when you execute the
same swap twice, it does not change the ordering of the items. if you
use tracing it only shows the trace for one of the postbacks, and
similarly response.Write does not help, so the event log is a sure way
to track it. the event log shows an event for Page_Load corresponding
to the first page access, then there are 2 Page_Load events and 2
RowCommand events, corresponding to the postback(s).

i'm grateful for any more clues you may have to try and get to the
bottom of this.
thanks
tim
Mar 23 '06 #26

P: n/a

Another request for microsoft to provide an official reply. I can verify
the exact behavior describe and add the following. This occurs only in
IE (v. 6 and v. 7). Additionally it occurs on both IIS5 and IIS6, as
well as the local Cassini server.
*** Sent via Developersdex http://www.developersdex.com ***
Feb 6 '07 #27

P: n/a
Hello JHirsch,

Is the Gridview command issue you mentioned here means the double postback
behavior of ImageButton in GridView command field? So far, there is only an
existing issue of this. You can have a look at the following newsgroup
thread to see whether the problem you met is exact the one there:

http://groups.google.com/group/micro...rk.aspnet.webc
ontrols/browse_thread/thread/a9a1bd53c27bd8b0/82c51830597e5fc8

Also, for this issue, there is already a public bug entry on the product
feedback center(also recorded in internal bug database):

http://connect.microsoft.com/VisualS...k.aspx?Feedbac
kid=105123

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 7 '07 #28

P: n/a
Hello JHirsch,

Is the bug entry I posted in last message the one meet your scenario?
Please feel free to let me know if there is anything else we can help.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Feb 9 '07 #29

This discussion thread is closed

Replies have been disabled for this discussion.