Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2008

Tip: Looking for answers? Try searching our database.

Shall I use an Event/Delegate way or just the compare value way?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mesut - 30 Jul 2008 09:10 GMT
Hi colleagues,

In fact I don't have a problem but just don't know which way is good
and better.

I need some advice which programming way I shall use. Since a couple
of days I'm investing my knowledge in Events and Delegates to get more
used to it.

Here I've situation which way should you use and why?

I've a page an ASPX page named. Creditlimit.aspx and a business logic
class Bank.cs.

In Creditlimit.aspx I'm setting the creditlimits for a customer.
e.g. customerID  A1001 has creditlimit 1250$, CustomerID B5404 has
creditlimit 1550$.
So I can set the creditlimit. I also have in another help table the
global creditlimit set value 2500$.
So no one customer should exceed this creditlimit. I mean when the
user enters 3500$ the application won't allow it to set.

I've solved this problem in 2 ways:

Way 1 - Traditional way:
-------------------------------------------------
In Creditlimit.aspx.cs (code behind)
I retrieve the global creditlimit calling a function in business logic
(class bank: method: GetglbCreditLimit) to get global creditlimit,
which returns me 3500$ and put that in an decimal field in aspx.cs
(code behind page).
then I compare the value (textbox control) with this value. If it
exceed the global credit limit it just send a status/error message to
the screen that it's not allowed. So I just compare the 2 field
values....

Ok this was the easy way. it's clear and easy.

Way 2 - Event Delegate way:
--------------------------------------------------
Here I'm using a delegate/event handler way.
I've created a Delegate and a event.

   public delegate void OverCreditLimit(object o,
CreditLimitEventArgs e);
   public class CreditLimit
   {
       public event OverCreditLimit NSF; //non-sufficient funds
....
then I'm calling the CheckOverlimit function in business logic in Bank
class. if the entered credilimit/requested credit limit is > than
GlobalCreditlimit, It trigger the event and invokes the delegate.

in aspx page I've set the eventhandler to property eventhandler
property see below...
           //check credit limit - it should not exceed the global
credit limit set up in UDC:Finance/Creditlimit
           Bank objBank = new Bank();
           objBank .NSF += CheckCreditLimitHandler;   // set to a
function that it diplays the error on the page

so when it exceeds CheckCreditLimit in Aspx.cs page displays the
error.

SO My question is in fact.... Both methods gives me the SAME result...
Why should I choose for the Event/Delegate method or why not?????????

I'm a little bit confused when to use event/delegates and when not? In
this circumstances would you use it or not?

thanks for sharing your thoughts,

mesut
Peter Duniho - 31 Jul 2008 06:40 GMT
> [...]
> SO My question is in fact.... Both methods gives me the SAME result...
> Why should I choose for the Event/Delegate method or why not?????????
>
> I'm a little bit confused when to use event/delegates and when not? In
> this circumstances would you use it or not?

You posted in the wrong newsgroup to get a really good answer.  One  
specific to ASP.NET would provide much better insight as to implementation  
details in this situation.

That said, for me the big issue is separation of different kinds of logic  
in your program and the ability to reuse your code.  In your first  
approach, your error handling is tied strongly to your user presentation.  
In the second, the code that handles the error handling and data analysis  
doesn't need to know anything at all about your user presentation.

This is often the distinction between using hard-coded callbacks and  
delegates/events.  So perhaps this is sufficient for your needs.  If not,  
I recommend asking people who are more knowledgeable about ASP.NET  
specifically.

Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.