473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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
Jul 30 '08 #1
1 1373
On Wed, 30 Jul 2008 01:10:06 -0700, mesut <me*********@noveonbe.comwrote:
[...]
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
Jul 31 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andy Read | last post by:
Hello all, I have the requirement to produce source code that produces an object hierarchy. Example: Root | Folder 1
3
by: Guadala Harry | last post by:
In the following line of code, what is the point of including the 'new' keyword? List.Changed -= new ChangedEventHandler(ListChanged); I'm just a bit confused because I thought 'new' was used...
15
by: Amit D.Shinde | last post by:
I am adding a new picturebox control at runtime on the form How can i create click event handler for this control Amit Shinde
20
by: Bob Day | last post by:
Using VS 2003, VB, MSDE... There are two threads, A & B, that continously run and are started by Sub Main. They instantiationsl of identical code. Thread A handles call activity on telephone...
6
by: David Veeneman | last post by:
I have several events that pass a value in their event args. One event passes an int, another a string, another a DateTime, and so on. Rather than creating a separate set of event args for each...
7
by: tony | last post by:
Hello! What is the differens if I use event handler onSizeChanged compare to using the other event handler MeltPracForm_SizeChanged. I see both as event handler is that right? I catch the event...
22
by: dvestal | last post by:
Suppose I have this: class C { public delegate void MyEventHandler(); public event MyEventHandler MyEvent; public void foo() { MyEvent(); // NullReferenceException? } }
0
by: pjr | last post by:
Using VS2005, I dynamically create an event delegate. Code follows question. My method gets the event's parameters and passes them onto a common event handler. My delegate gets called when expected...
4
by: tshad | last post by:
I am just getting started with events and had a couple of questions on why they do what they do. If you have a textbox and you want to handle an event you can just do: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.