datagrid 事件不能工作. (Why sometimes datagrid event cannot be fired?)

Well, there have been many questions regarding why in a datagrid the ItemCommand does not fire when using Push Buttons, but when using LinkButtons, everything works as expected.

So here is the skinny...

When using a LinkButton, you see in the Status Bar the following:

javascript: __doPostBack('Northwind:_ctrl1:_ctrl3','');

This causes the following to happen:

  theform.__EVENTTARGET.value = eventTarget;
  theform.__EVENTARGUMENT.value = eventArgument;

With this in place, the Eventtarget picked up by the CLR on PostBack, raises the PostBack Event and will fire the event even if you Re-bind over the DataGrid.  This seems to work fine no matter what because of this javascript function.

When you use the PushButton, it is merely a submit button and the name of the submit button would be the 'Northwind:_ctrl1:_ctrl3' so that the event target would still be there, but it would not get put in place until the events were processed.  So in this case if you Re-Bind your Datagrid in your Page_Load then it overwrites the event and it does not fire.

This is the great reason that when you are doing PostBack and you have a Binding Process that happens in the Page_Load, make sure you test for PostBack before you rebind. 

C#:
if(!IsPostBack) {
  //  do something
}

VB:
If Not IsPostBack Then
  ' do something
End If

Then you will not have problems with your PostBack events with a DataGrid.

转载于:https://www.cnblogs.com/yangbin990/archive/2005/07/15/193526.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值