StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Raising the ErrorSavingEventExpand / Collapse
Author
Message
Posted 12/07/2006 9:17:36 AM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: Forum Members
Last Login: 06/19/2008 11:16:33 AM
Posts: 73, Visits: 12,471
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.

Thanks guys,

CT
Post #5047
Posted 12/07/2006 10:16:38 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 2 days ago @ 5:02:56 PM
Posts: 2,682, Visits: 1,882
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




www.bungie.net
Post #5056
Posted 12/07/2006 10:53:02 AM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: Forum Members
Last Login: 06/19/2008 11:16:33 AM
Posts: 73, Visits: 12,471
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

Post #5058
Posted 12/07/2006 10:58:52 AM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: Forum Members
Last Login: 06/19/2008 11:16:33 AM
Posts: 73, Visits: 12,471
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

  Post Attachments 
RaisingErrorSaving.jpg (31 views, 57.15 KB)
Post #5059
Posted 12/07/2006 11:04:37 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 2 days ago @ 5:02:56 PM
Posts: 2,682, Visits: 1,882
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...


www.bungie.net
Post #5061
Posted 12/07/2006 12:37:54 PM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: Forum Members
Last Login: 06/19/2008 11:16:33 AM
Posts: 73, Visits: 12,471
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
Post #5075
Posted 12/07/2006 1:11:56 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 4:58:13 AM
Posts: 4,379, Visits: 4,421
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.
Post #5078
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 1:32pm

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.109. 12 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.