【问题标题】:How do I Prevent FormView from clearing user's entered Values after Insert Method has fired?Insert 方法触发后,如何防止 FormView 清除用户输入的值?
【发布时间】:2010-02-26 16:08:36
【问题描述】:

我一直在努力让 FormViews 按照 Microsoft 期望的方式工作大约一天,并想出了一堆很棒的东西。

我可以在 ObjectDataSource.Inserting 事件处理程序中捕获 e.Exception 和 e.ReturnValue,我什至可以通过检查 e.ObjectInstance 来欺骗和检查 ObjectDataSource.ObjectDisposing 中的对象的其他属性......我什至学会了FormView 的插入处理程序在 ObjectDisposing 处理程序之后运行,因此如果发现问题,我仍有时间对其做出反应,并将 FormView 上的 e.KeepInInsertMode 设置为 true。

我的问题是,用户在插入表单中输入的值似乎被清除了。

那么,如何防止 FormView 在其 Insert 方法触发后被清除?

(使用 ASP.NET + VB)

我不认为在这里发布我的代码真的会有什么好处,我必须对其进行修改以删除机密的业务逻辑内容......所以我现在将跳过它。

编辑:

我找到了一个临时的、公认的非常麻烦的解决方案(以防没有人找到解决问题的真正解决方案)。

我有一个页面变量定义为:

Dim eInsertArgs As FormViewInsertedEventArgs

然后我在我的 ItemInserted 处理程序中执行以下操作

    If boolInsertErrorOccurred = False Then
        e.KeepInInsertMode = True
        eInsertArgs = e
    Else
        eInsertArgs = Nothing
    End If

然后在每个控件上我都有这样的控件数据绑定事件:

    If IsNothing(eInsertArgs) = False Then
        Dim _sender As TextBox = sender
        _sender.Text = eInsertArgs.Values("_FieldName")
    End If

这样做的效果是,在 ASP.NET 将 FormView 绑定到默认(空白)模板之后,我将值设置回提交的值。

请帮我找到一个不那么糟糕的解决方案。 :)

【问题讨论】:

  • 您应该提交您的编辑并附上解决方案作为答案。

标签: asp.net vb.net insert objectdatasource formview


【解决方案1】:

您需要创建自己的服务器控件,该控件继承自 FormView 控件。

Public Class MyFormView
     Inherits FormView

Protected Overrides Sub OnDataSourceViewChanged(ByVal sender As Object,
ByVal e As EventArgs)
     If (MyBase.CurrentMode = FormViewMode.Insert) Then
           MyBase.RequiresDataBinding = False
     Else
           MyBase.OnDataSourceViewChanged(sender, e)
     End If
End Sub

End Class

请看这个页面:http://www.dotnetmonster.com/Uwe/Forum.aspx/asp-net/76885/FormView-Insert

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-10
    • 2017-07-08
    • 2021-12-24
    • 1970-01-01
    • 2014-02-14
    • 2021-11-25
    • 2012-09-23
    相关资源
    最近更新 更多