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="Event WireupPage.aspx .cs" Inherits="Event WireupPage" Trace="true"
%>
<!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:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:LocalNorthWi nd %>"
SelectCommand=" SELECT [CategoryID], [CategoryName],
[Description] FROM [Categories]">
</asp:SqlDataSour ce>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateCol umns="False" DataKeyNames="C ategoryID"
DataSourceID="S qlDataSource1"
OnRowCommand="G ridView1_RowCom mand">
<Columns>
<asp:BoundFie ld DataField="Cate goryID"
HeaderText="Cat egoryID" InsertVisible=" False"
ReadOnly="True" SortExpression= "CategoryID " />
<asp:BoundFie ld DataField="Cate goryName"
HeaderText="Cat egoryName" SortExpression= "CategoryNa me" />
<asp:BoundFie ld DataField="Desc ription"
HeaderText="Des cription" SortExpression= "Descriptio n" />
<asp:ButtonFiel d CommandName="Mo veUp" Text="MoveUp" />
<asp:ButtonFiel d CommandName="Mo veDown" Text="MoveDown" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
==========code behind========= =
public partial class EventWireupPage : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
Trace.Write("Pa ge_load " + DateTime.Now.To LongTimeString( ) );
}
protected void GridView1_RowCo mmand(object sender,
GridViewCommand EventArgs e)
{
Trace.Write("Ro wCommand " + e.CommandName + " " +
DateTime.Now.To LongTimeString( ));
}
}
=============== =====
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+3hSkc5a7 PT+ar2/nTIb7cww==
| X-WBNR-Posting-Host: 70.68.38.48
| From: "=?Utf-8?B?UGhpbGxpcCB XaWxsaWFtcw==?= "
<Ph************ **@webswapp.com >
| References: <11************ **********@z14g 2000cwz.googleg roups.com>
<B6************ *************** *******@microso ft.com>
<11************ **********@g44g 2000cwa.googleg roups.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************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGXA03.phx .gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3656 26
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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_RowCo mmand
| > 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
| >
| >
|