1

我在 UpdatePanel 中有一个具有查看和编辑模式的 FormView:

<asp:UpdatePanel runat="server">
    <ContentTemplate>
        <asp:FormView runat="Server" DefaultMode="ReadOnly" DataSourceID="_myDataSource" >
            <ItemTemplate>

                <!-- View controls omitted -->
                <asp:Button runat="server" CommandName="Edit" Text="Edit" />
            </ItemTemplate>

            <EditItemTemplate>

                <!-- Edit controls omitted -->
                <asp:Button runat="server" CommandName="Update" Text="Save"  />
                <asp:Button runat="server" CommandName="Cancel" Text="Cancel" CausesValidation="false" />
            </EditItemTemplate>
        </asp:FormView>
    </ContentTemplate>
</asp:UpdatePanel>

 <!-- Data source (may attributes omitted) -->
<asp:ObjectDataSource ID="_myDataSource" runat="server" />

和按钮/命令工作正常EditUpdateCancel按钮什么也不做。

有任何想法吗?

4

1 回答 1

2

该页面可能似乎没有闪烁,但在单击“取消”按钮时,FormView 引发了 2 个事件,并且确实发生了回发。你可以参考MSDN。(备注部分下的表格)

“取消”按钮的作用是:

Cancels an edit or insert operation and returns the FormView control to the mode specified by the DefaultMode property. Raises the ModeChanged and ModeChanging events.

因此,您需要处理 ModeChanged 和 ModeChanging 的事件,如下所示:

<asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource" allowpaging="true" datakeynames="EmployeeID"
        onmodechanged="EmployeeFormView_ModeChanged"  
        onmodechanging="EmployeeFormView_ModeChanging"
        runat="server">

因此,您希望在单击“取消”按钮后运行的任何代码都应根据要求使用这两个事件。

我在 Page_Load、modeChanging() 和 modechanged() 中放置了调试器,所有三个事件都在单击“取消”按钮时依次触发。

于 2013-07-23T15:31:30.470 回答