【问题标题】:Debugging GridView / ObjectDataSource events调试 GridView / ObjectDataSource 事件
【发布时间】:2012-01-23 22:28:14
【问题描述】:

喂!

我正在使用绑定到 ObjectDataSource 的 ASP.NET GridView 控件:

<asp:ObjectDataSource ID="Things" runat="server"
    TypeName="BLL.Thing"
    UpdateMethod="UpdateThing"
    OnUpdating="Things_Updating"
    OnUpdated="Things_Updated">
    <UpdateParameters>
        <asp:SessionParameter
            Name="userContext"
            SessionField="UserContext"
            Type="Object" />
        <asp:Parameter Name="thing" Type="Object" />
    </UpdateParameters>
</asp:ObjectDataSource>

单击带有 CommandName="Update" 的 ImageButton 控件会导致发生指定的 OnUpdating 事件,但不会发生指定的 UpdateMethod 或 OnUpdated 事件。

<EditItemTemplate>
    <asp:ImageButton ID="ImageButton_Save" runat="server"
        CommandName="Update"
        SkinID="Save"
        CausesValidation="false"
        CommandArgument='<%# Eval("Id") %>' />
    <asp:ImageButton ID="ImageButton_Cancel" runat="server"
        CommandName="Cancel"
        SkinID="Cancel"
        CausesValidation="false" />
</EditItemTemplate>

输入参数在 OnUpdating 事件中定义如下:

protected void Things_Updating(object sender, ObjectDataSourceMethodEventArgs e)
{
    e.InputParameters["thing"] = _theThing;
}

不抛出异常。该页面刚刚回发,仍然显示 EditItemTemplate 控件。我可以在所有地方设置断点,但路径会在 Things_Updating 结束时停止。似乎发生了一些异常,调试器没有处理或捕获。有没有办法打开引擎盖看看 ASP.NET 正在做什么(或没有做什么)?

提前致谢!

【问题讨论】:

    标签: c# asp.net objectdatasource edititemtemplate


    【解决方案1】:

    BLL.Thing.UpdateThing() 会执行吗?这应该在Things.Updating 之后发生并且易于调试。另外,如果有什么东西导致了异常,那可能就是它了。

    编辑:

    尝试在 GridView.RowUpdating 而不是 ObjectDataSource.Updating 的处理程序中添加参数。这就是我通常的做法。我认为您需要获取DataSourceView 来修改ObjectDataSource 事件中的更新参数。 (见:ObjectDataSource Gridview Insert Fails W/ Empty Values Dictionary

    protected void gridThings_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        e.NewValues.Add("thing", _theThing);
    }
    

    【讨论】:

    • 不,这条线索在 Things_Updating 之后神秘地结束了:-/
    • 我认为 GridView 类没有 OnUpdating 事件,但它确实有一个我将使用的 RowCommand 事件。谢谢!
    • @Adam 我的错误,我的意思是引用GridView.RowUpdating。谢谢采纳!
    【解决方案2】:

    想到两件事可能会导致进度停在那里:

    1. 您还处理了他的GridView.RowUpdating 事件,并将GridViewUpdateEventArgs.Cancel 属性设置为true。像这样的:

      protected void myGridView_RowUpdating(Object sender, GridViewUpdateEventArgs e)
      {
          e.Cancel = true;
      }
      
    2. 您在ObjectDataSource.Updating 事件中做了类似的事情,将ObjectDataSourceMethodEventArgs.Cancel 属性设置为false。像这样:

      private void myObjectDataSource_Updating(object source, ObjectDataSourceMethodEventArgs e)
      {
          e.Cancel = true;
      }
      

    其中任何一个都会停止更新过程,导致出现您所描述的情况。

    【讨论】:

    • 谢谢,合作伙伴。我有条件逻辑在某些情况下将 e.Cancel 设置为 true,但它们没有被击中。我将放弃这种方法,而是在 RowCommand 事件中使用我自己的方法。
    • @Adam 拍得好!那么祝你好运=)
    猜你喜欢
    • 1970-01-01
    • 2011-04-23
    • 1970-01-01
    • 2020-06-30
    • 1970-01-01
    • 2012-01-13
    • 1970-01-01
    • 2013-07-29
    • 1970-01-01
    相关资源
    最近更新 更多