这可能是我没有完全遵循的页面生命周期,但我有以下问题。我有一个 gridview 对象和一个 formview 对象。单击网格视图时,将填充表单视图。
当我处于表单视图插入模式时,一切正常。当我处于 formview 编辑模式时,按钮无法到达 ItemCommand 方法。我通过在代码中添加断点来测试这一点,每次插入方法中的保存按钮都会到达命令,但不会到达编辑模式。
从编辑项目模板
从 InsertItemTemplate :
FormView
现在,我真的不希望 ViewState 中存在这种形式的项目,但无论如何我尝试启用视图状态。当我启用它时,可以正确访问 ItemCommand 方法。但是...如果我单击“编辑”、“取消”、“编辑”,我会收到一个巨大的 ViewState 错误(可能是因为我的 FormView 在页面生命周期的中间以编程方式更新)。
有人可以在这方面为我提供一些帮助吗?我不知道如何让编辑项实际触发命令,除非我使用 ViewState (我真的不想这样做)并且这会产生它自己的错误。
谢谢。
This is probably a page life cycle thing I'm not completely following, but I have the following problem. I have a gridview object and a formview object. When the gridview is clicked, the formview is populated.
When I am in formview inserting mode, everything works perfectly. When I am in formview edit mode, the buttons do not reach the ItemCommand method. I have tested this by adding a breakpoint to my code and every time, the save button from the insert method reaches the command but not the edit mode.
from the EditItemTemplate
<asp:Button ID="btnSave" runat="server" CommandName="Update"
Text="Save" meta:resourcekey="btnSaveResource2" />
<asp:Button ID="btnCancel" runat="server" CommandName="Cancel" Text="Cancel"
meta:resourcekey="btnCancelResource2" />
From the InsertItemTemplate :
<asp:Button ID="btnAdd" runat="server" CommandName="Insert"
Text="Save" meta:resourcekey="btnAddResource1" />
<asp:Button ID="btnCancel" runat="server" CommandName="Cancel" Text="Cancel"
meta:resourcekey="btnCancelResource3" />
FormView
<asp:FormView ID="poolEditFV" runat="server" OnItemCommand="poolEditFV_ItemCommand"
EnableViewState = "False" OnModeChanging="poolEditFV_ModeChange"
meta:resourcekey="poolEditFVResource1">
Now, I don't really want the items in this form in the ViewState, but I tried enabling the view state anyhow. When I enable it, the ItemCommand method is properly reached. However... if I clicked edit, cancel, edit, I get a huge ViewState error (probably because my FormView is being updated programmatically in the middle of the page's lifecycle).
Can anyone offer me some help on this one? I don't know how to get the edit items to actually fire commands unless I use the ViewState (which I don't really want to) and that creates errors of its own.
Thank you.
发布评论