请帮忙请看GridView命令+ AutoEventWireUp,两次触发...... [英] help please on GridView commands + AutoEventWireUp, firing twice etc...

查看:48
本文介绍了请帮忙请看GridView命令+ AutoEventWireUp,两次触发......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是.net 2.0的新手,我刚刚开始掌握

gridview。

我的页面将autoEventWireUp设置为true,我收集的应该是

根据您的

方法名称确定哪些处理程序在适当的时候调用。

GridView具有OnRowCommand =" GridView1_RowCommand"在aspx中。


我的问题是,RowCommand事件在页面上触发两次(

时间的95%)。另外5%它只发射一次。根本没有

的一致性。

.net 1.1中的
,我会理解代码隐藏在接线上

事件,而aspx正在做同样的事情,所以这将导致

在事件被提升两次。但是,在.net 2中,我找不到任何

代码隐藏的功能(甚至可以查看temp.asp.net

文件)。


如果我设置autoEventWireUp = true,在

GridView aspx中声明的OnRowCommand,Page_Load会触发两次,GridView1_RowCommand也会触发。


如果我设置AutoEventWireup = false,则PageLoad不会触发(如预期的那样)

和GridView1_RowCommand仅触发一次。但偶尔它会两次点燃
。这很痛苦!有人请我摆脱苦难:-)


这里是我的代码:

******** ASPX ***** ****

<%@ Page Language =" C#" AutoEventWireup =" false"
CodeFile =" TestGridView.aspx.cs"继承= QUOT; 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 ="图片"

CommandName =" MoveUp" ImageUrl =" ../ Images / Move_Up.gif"

Text ="将此页面向上移动一个位置 />

< asp:ButtonField ButtonType =" Image"

CommandName =" MoveDown" ImageUrl =" ../ Images / Move_Down.gif"

Text ="将此页面向下移动一个位置 />

< / Columns>

< / asp:GridView>

< asp:ObjectDataSource ID =" dsPages" runat =" server"

SelectMethod =" Select" TypeName =" PageManager">

< / asp:ObjectDataSource>

< / form>

< / body>

< / html>

**********代码背后***********

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>");

}

}


我所做的就是在两个事件中放置断点,调试并保持

点击上/下按钮,直到你看到事件被击中两次一个

点击。


谢谢

tim

推荐答案

您好蒂姆,


您无需指定On RowCommand如果你有autoEventWireUp

= true。

-

HTH,

Phillip Williams
http://www.societopia.net
http://www.webswapp.com

" Tim_Mac"写道:
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:

我是.net 2.0的新手,我刚刚开始掌握
gridview。
我的页面将autoEventWireUp设置为true,我收集的应该根据你的
方法名称确定哪些处理程序在适当的时候调用。
GridView有OnRowCommand =" GridView1_RowCommand"在aspx中。

我的问题是RowCommand事件在页面上触发两次(
时间的95%)。另外5%它只发射一次。根本没有
一致性。

在.net 1.1中,我会理解代码隐藏事件正在接通事件,而aspx正在做同样的事情,所以这将导致
在事件被提升两次。但是,在.net 2中,我找不到任何代码隐藏的功能(甚至可以查看temp.asp.net文件)。

如果我设置了autoEventWireUp = true,并且在GridView aspx中声明了OnRowCommand,则Page_Load会触发两次,GridView1_RowCommand也会触发。
如果我设置AutoEventWireup = false,则PageLoad不会触发(正如预期的那样)
和GridView1_RowCommand只触发一次。但偶尔会发射两次。这很痛苦!有人请我摆脱苦难:-)

这是我的代码:
******** ASPX *********
<%@ Page Language =" C#" AutoEventWireup =" false"
CodeFile =" TestGridView.aspx.cs"继承= QUOT; 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 ="将此页面向上移动一个位置 />
< asp:ButtonField ButtonType =" Image"
CommandName =" MoveDown" ImageUrl =" ../ Images / Move_Down.gif"
Text ="将此页面向下移动一个位置 />
< / Columns>
< / asp:GridView>
< asp:ObjectDataSource ID =" dsPages" runat =" server"
SelectMethod =" Select" TypeName =" PageManager">
< / asp:ObjectDataSource>
< / form>
< / body>
< / html>

**********代码背后***********
公共部分类Admin_TestGridView:System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
Response.Write(" Page_Load< HR>");
}

受保护的void GridView1_RowCommand(对象发送者,
GridViewCommandEventArgs e)
Response.Write(" GridView1_RowCommand< HR>");
}
}
<我所做的是在两个事件中都设置断点,调试并保持单击向上/向下按钮,直到你看到一次点击事件两次点击。

谢谢
时间

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



嗨菲利普,谢谢你的回复。

ok so那就是应该发生的事情,我会同意你的意见。

除了...当我设置autoEventWireUp = true时,当我点击其中一个按钮字段时,根本不会引发GridView1_RowCommand

事件,并且

Page_Load单击按钮时会触发两次。当页面首次加载时,它只会触发一次。


我使用的代码与上面发布的完全相同,除了

OnRowCommand已从gridView aspx中删除,并且

autoEventWireUp已更改为true。


为什么Page_Load会激发两次,为什么autoEventWireUp不能这样做吗?b $ b它的工作是连接我的RowCommand事件处理程序吗?


谢谢

tim

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


你好蒂姆,


感谢您的回复。这个讨论让我纠正了一些关于AutoEventWireUp属性的误解。


这是我通过研究这个话题找到的:

1- AutoEventWireUp仅适用于页面事件。有关页面事件的解释


http://msdn2.microsoft.com/en-us/lib...US,VS.80).aspx

2-即使

你有AutoEventWireUp = true,你也必须连接页面内控件的事件。当你通过在服务器中为你添加标记来双击控件时,VS.Net会自动执行此操作

控制。


为了验证我的发现,我在您发布的代码中创建了3个演示

之前:

1-在此演示中,AutoEventWireUp设置为true并且事件启动

两次,因为我还覆盖了OnInit方法,并为其中的控件添加了事件接线


http://www.webswapp.com/CodeSamples/...rue_Error.aspx


2-在这个演示中,AutoEventWireUp设置为true,一切都工作为

预期
http://www.webswapp.com/CodeSamples/...reUp_True.aspx


3-在此演示中,AutoEventWireUp设置为false(我的优先选择

编程,因为它可以提高性能)并且一切都按预期工作
http://www.webswapp.com/CodeSamples/...eUp_False.aspx


-

HTH,

Phillip Williams
http:// www .societopia.net
http://www.webswapp.com

" Tim_Mac"写道:
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:
嗨菲利普,谢谢你的回复。
好的,这就是应该发生的事情,我会同意你的意见。
除外。 ..当我设置autoEventWireUp = true时,当我点击其中一个按钮字段时,根本不会引发GridView1_RowCommand
事件,而当我点击按钮时,Page_Load会触发两次。它只在首次加载页面时触发一次。

我正在使用的代码与上面发布的代码完全相同,除了
OnRowCommand已从gridView中删除aspx和
autoEventWireUp已经改为true。

为什么Page_Load会激发两次,为什么autoEventWireUp不会这样做呢?它是连接我的RowCommand事件处理程序的工作?

感谢
时间
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



这篇关于请帮忙请看GridView命令+ AutoEventWireUp,两次触发......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆