Is client-side JScript allowed?

L

Larry David

Hi,

I'm just trying to wrap my mind around the ASP.NET model. Let me walk
you through a trivial scenario:

Let's say I have a form containing a text box where the user enters his
name. It also contains a button, labeled "Process Now!" My goal is to
examine the user's name and upload it into a database.

Since all of the elements (the form, the text box, and the button) have
a runat=server attribute, my server-side code will have access the value
entered into the text box when the user clicks the "Process Now" button.

Now it turns out that I don't want to allow users who enter the name
"Hulio Von Nostrom" to be able to process the form [bare with me -- it's
just an example for educational purposes]. I could check the user's name in
my SERVER code easily enough and then present the user with an error
message -- but what if I want to do a bit of client side validation using
JScript *first* ?

What I want to do is handle the Process button's click event in JScript,
giving it first crack at validating the name. If validation fails, I want to
alert the user (via window.alert()) without a roundtrip to the server. That
way, if the user enters "Hulio Von Nostrom", I can short-circuit the ensuing
HTTP request to my server. If the user enters any OTHER name, my JScript
code won't take any action and server processing should take place normally.
So my questions are:

1) Is there a way to somehow register my client-side JScript code to get
called PRIOR to a server-side event being generated when the Process button
is clicked?
2) What action do I take in my JScript code to short-circuit the HTTP
request? What action do I take to allow processing to take place normally?

I think that I understand ASP.NET -- it's just the interaction between
ASP.NET and traditional client side JScript that confuses me.

Thanks,

Larry David

P.S. No, I'm not the same Larry David that created Seinfeld. :)
 
K

Kevin Spencer

Hi Larry,

Microsoft has created a good number of common types of functionality for
ASP.Net pages, in the form of the object model, and various Server Controls.
However, that doesn't mean that Microsoft has created a model or Control for
every situation. And Microsoft doesn't expect everyone to write an
application "the same way" (whatever THAT is!). In fact, ASP.Net and the
..Net platform are designed to allow you as much control over your app as you
like. Why, you can even create your own custom HTTP Handlers if necessary.
So, if you want to use client-side javascript to validate your form data,
feel free.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top