client side vs server side events for controls

M

Mong

Hi,

I have a webform with various asp controls on it such as textboxes and
dropdownlists. I'm fairly new to asp.net coming from VB6 and am
wondering when it's best to use client side events and when it's best
to use server side events.

For example, if a textbox is to contain a date I want to validate the
date when that textbox loses the focus. If the date is not valid I
make visible a label next to the textbox telling the user it's
invalid. At the moment I'm doing this in the server side TextChanged
event for the textbox and have noticed this is fairly slow.I'm
thinking this kind of thing should be done on the client side - would
that be correct?

If so, how do I do this?

Also, is there a reference out there which shows all the available
client side events these asp (web form) controls have and how to
implement them?

I'm assuming you would code these using Javascript. Are there any
alternatives or is that the standard? Should VBScript be left alone as
it seems to me it's being fazed out now that asp.net can use native VB
on the server side? Or is that a mute point as my understanding is
client side and server side are two seperate entities?

So many questions!

Thanks for any replies.

Regards,

Mong
 
W

WJ

"Mong"
when it's best to use client side events

Whenever you do not depend on server for data validation.
and when it's best to use server side events.

Whenever you depend on server to retrieve data such as verifying if certain
pieces of data match with those entered on the form by the client.
For example, if a textbox is to contain a date I want to validate the
date when that textbox loses the focus. If the date is not valid I
make visible a label next to the textbox telling the user it's
invalid. At the moment I'm doing this in the server side TextChanged
event for the textbox and have noticed this is fairly slow.

This is good. Nothing wrong with it. Slowness depends on bandwidth and your
server (hardware) capacity. If you have a form that has 50 fields on it, it
is run on T1 and your server has about 1GB RAM and its clock speed is approx
600MHZ or above, it is fairly quick. I say this for no more than 50
concurrent hits (conservative).
I'm thinking this kind of thing should be done on the client side - would
that be correct?

It is a perfect solution, this saves you a trip back and forth between CS.
However, some clients donot like to enable Java script or any client side
scripts. Judge it yourself if you should or should not enforce certain
things on clients. For Intranet, this is easier because you know who your
users are.
If so, how do I do this?

Use Java script or VB script (Very Bad). I prefer JS. If you use
MS/FrontPage, you can enable field validation easily. FP will create JS or
VB scripts for you. Or you can hand code it yourself. For a sample, please
visit this site: http://javascript.internet.com/forms/validate-date.html
Also, is there a reference out there which shows all the available
client side events these asp (web form) controls have and how to
implement them?

Plenty at http://www.google.com, once there, enter a search term of your
choice such as "how to code event in javascript"
I'm assuming you would code these using Javascript.?

Yes, it is the best
Should VBScript be left alone as...

VBS=Very Bad Sh....
So many questions!

Be expert on 1 thing only. Donot try too many, let someone else has a chance
to make a few $ too. Your life is short ! Reserve some for deep-sea fishing
later... and never give everything to your boss entirely !

Happy .Netting

John
 
D

DalePres

Web Server Controls don't have client side events. HTML Server Controls
(HTML Controls set to runat=server) have onclick and onload events.

Here's a great article on HTML Server Controls and when you might want to
use them: (watch for line breaks...make sure you get the whole thing.)

http://msdn.microsoft.com/library/d...n-us/dnaspp/html/ASPNet-ForgottenControls.asp

Along with what's in that article, one big reason I consider when choosing
Web Server controls or HTML Server controls is the target audience. In an
intranet situation, the postback of web server controls isn't such a big
issue, but on the internet, with dial-up users, postback can be a real pain
in the axle and using HTML Server controls lets you do more on the client
side and then postback less often.

Hope that helps.

Dale
 
R

Rick Spiewak

You can use the validation controls to do client-side validation, they
generate their own javascript to do so. You should then check the
page.isvalid property on postback, just to be sure.
 
M

Mong

Thanks very much for your replies, very helpful!

Just one further question regarding VBScript - everyone keeps
condemning the use of it compared to JavaScript but no one really
explains why, so why is it so bad?
 
K

Kevin Spencer

Client-side VBScript is not supported by all browsers. JavaScript is.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top