How to prevent FormView from clearing user-entered values ​​after running the Insert method?

I struggled to get FormViews to work the way Microsoft expects me to be around for one day, and I will have a great thing.

I can catch e.Exception and e.ReturnValue in the ObjectDataSource.Inserting event handler, and I can even fool and check other Object properties in ObjectDataSource.ObjectDisposing by checking e.ObjectInstance ... and I even found out that the FormView Inserting Handler is running AFTER the handler ObjectDisposing, so if there is a problem, I still have time to respond to it, and e.KeepInInsertMode is true in FormView.

My problem is that the values ​​entered by the user into the Insert form are cleared independently.

So, how can I prevent FormView from clearing after it enters the Insert method?

(using ASP.NET + VB)

I don’t think that putting my code here will really bring much benefit, and I will have to modify it to cut off the confidential business logic ... so I will skip it for now.

edit:

I found a temporary and admittedly terrible solution (in case no one finds a REAL solution to the problem).

I have a page variable defined as:

Dim eInsertArgs As FormViewInsertedEventArgs

And then I do the following in the ItemInserted handler

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

Then on each of the controls, I have something like this in the control data binding event:

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

The effect of this is that I set the BACK values ​​for the presented values. AFTER ASP.NET associates FormView with the default template (empty).

, .:)

+5
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

+1

All Articles