Raising the ErrorSavingEvent


Author
Message
Charles Thomas Blankenship...
Charles Thomas Blankenship
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Awaiting Activation
Posts: 172, Visits: 12K
Howdy StrataFramers:



I'm trying to handle the ErrorSaving event of a business object that is used on an .ASPX page and that is referenced in the ApplicationBasePage as such.



Public WithEvents oPrefix As Prefix



On the page where the saving is taking place I put the following code as per the help topic ErrorSaving:



Private Sub ErrorSaving(ByVal e As MicroFour.StrataFrame.Business.ErrorSavingEventArgs) Handles oPrefix.ErrorSaving



Dim lcErrorText As String = ""

lcErrorText = Me.GenerateWarningTable(e.ToString)

SetErrorsLabelState("Show", lcErrorText)



End Sub



But I get an error saying the signatures do not match. It looks like the ErrorSaving example caters to WinForms so I guess my question is how do I snag this event in an ASPX page so I can capture the Unique Key Violation message from the database and display it to the user. I tried the same thing in the web example from Micro4 and the same error occurs. I guess I'm doing the same thing incorrectly in both places. Wink



Thanks guys,



CT

Charles T. Blankenship
Senior Consultant
Novant Consulting, Inc.
704.975.7152
http://www.novantconsulting.com
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Well, CT, I'm not sure.  My quick sample didn't give me any errors when adding a new handler to the ErrorSaving event of a business object.  I defined the business object within the ApplicationBasePage and then added this code to my Default.aspx.vb file and it compiles fine.  Does it give you an error at runtime?

Public Sub HandleErrorSaving(ByVal e As MicroFour.StrataFrame.Business.ErrorSavingEventArgs) Handles MyBO.ErrorSaving

End Sub


Charles Thomas Blankenship...
Charles Thomas Blankenship
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Awaiting Activation
Posts: 172, Visits: 12K
It gives the error during design time ... what I want to happen is to trap the ErrorSaving event in the ASPX codebehind page when it happens so I can rip the message out of the e argument and display it to the user. So, my first question probably should be "Can I trap the ErrorSaving event in the codebehind page of an ASPS form?) And, I'm quite sure the answer to that question is, yes.



The next thing that I tried to do is to add an error handler to the Prefix class like follows:



Public Sub Prefix_ErrorSaving(ByVal e As MicroFour.StrataFrame.Business.ErrorSavingEventArgs)

Me.ESEA = e



End Sub



(Ignore the code inside of that Public Sub ... I was just playing around with a work-around that is not viable.)



Next, I added the following code to the codebhind page



Private Sub ErrorSaving(ByVal e As MicroFour.StrataFrame.Business.ErrorSavingEventArgs) Handles oPrefix.Prefix_ErrorSaving



Dim lcErrorText As String = ""

lcErrorText = Me.GenerateWarningTable(e.ToString)

SetErrorsLabelState("Show", lcErrorText)



End Sub



Now I get the error message that says event Prefix_ErrorSaving cannot be found.



Realize that this is the second iteration of me trying to pull my head out of my arse. The only thing I really need is to learn how to trap the ErrorSaving event in the codebhind page so I can get to the ErrorSavingEventArgs message. Note: Do not assume I know jack shyte about what I am doing in this instance, treat the answer as you would to a suckling babe.



Another way to phrase this (from a superclass code perspective) is



The superclass of the business object tries to raise the ErrorSaving event but the following code



RaiseEvent(ByVal e As ErrorSavingEventArgs)

'-- See if we can directly invoke the event

If Me._Handler_ErrorSaving IsNot Nothing Then

If (Me._SyncObject IsNot Nothing) AndAlso (Me._SyncObject.InvokeRequired) Then

Me._SyncObject.Invoke(Me._Handler_ErrorSaving, New Object() {e})

Else

Me._Handler_ErrorSaving.Invoke(e)

End If

End If

End RaiseEvent



sees that Me._Handler_ErrorSaving was nothing. However, adding the following code to the business object caused this problem to go away ...



Public Sub Prefix_ErrorSaving(ByVal e As MicroFour.StrataFrame.Business.ErrorSavingEventArgs)

Me.ESEA = e



End Sub



But forced me to have to do something stupid like added a custom property to the business object that stores the "e" parameter ... which I access after the save fails ... hoo hisss.



I want the e parameter directly delivered to the code behind page so I can display the error ... but it is soooo dark in here.



I think this just about covers my cranial rectal inversion



Tongue

Charles T. Blankenship
Senior Consultant
Novant Consulting, Inc.
704.975.7152
http://www.novantconsulting.com
Charles Thomas Blankenship...
Charles Thomas Blankenship
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Awaiting Activation
Posts: 172, Visits: 12K
Here is what the code and the error looks like ... it looks like what you put in your post is exactly what I tried. Hummm ... obvious missing something silly here.



CT

Charles T. Blankenship
Senior Consultant
Novant Consulting, Inc.
704.975.7152
http://www.novantconsulting.com
Attachments
RaisingErrorSaving.jpg (127 views, 57.00 KB)
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Well, that is the exact same code that I added to my website.  So, the only thing that I can think of is that maybe it thinks that the signatures are incorrect because DLLs referenced might not be the same version?  Check your web.config file for the website and make sure the DLLs are on 1.5.0.0 and you might rebuild your business object library just to make sure.  I've seen problems when the website was referencing Release DLLs and the BOLibrary was referencing the Debug DLLs, they thought they needed to pull from 2 different folders.

But, by all means, that should work perfectly...

Charles Thomas Blankenship...
Charles Thomas Blankenship
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Awaiting Activation
Posts: 172, Visits: 12K
You ain't gonna believe this but I removed all of my custom code from the business object (AddHandler, custom method, mapping the event to the method in the object itself) and reran the code. Guess what, the error is still there in design time but the event is surfacing as expected now. It even runs twice (I put a Breakpoint in there just to make sure). Sure enough, the event loops twice.



Why is this code executing even though the design time is registering an error? Sometimes this stuff makes me feel nuttier than a fruitcake.



CT

Charles T. Blankenship
Senior Consultant
Novant Consulting, Inc.
704.975.7152
http://www.novantconsulting.com
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
When code starts executing twice, this is generally a sure fire indication that you have more than one handler.  Since an event can be managed by multiple handlers, if the handler is not removed (or one gets added that is not expected) then you have code re-execution.  This doesn't sounds like a BO issue...it is more than likely coming from a handler you have added someplace...and keep in mind you are working on the web, so if the form is posted and you did not remove the previous handler, you could then have multiple handlers.  Be sure to keep the IsPostBack property in mind on the web when manually creating or adding handlers.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search