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