472,958 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 1360
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.