471,122 Members | 1,019 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Is client-side JScript allowed?

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. :)


Nov 19 '05 #1
3 1498
You should use a CustomValidator for your text box. One of its properties is
the ClientValidationFunction. This client side method will be called during
normal client side page validation.

http://msdn.microsoft.com/library/de...ctiontopic.asp

bill

"Larry David" <My***************@HealthyChoice.org> wrote in message
news:Nv********************@giganews.com...
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. :)

Nov 19 '05 #2
"Larry David" <My***************@HealthyChoice.org> wrote in message
news:Nv********************@giganews.com...

Take a look at Attributes.Add for your button.

http://www.dotnetextreme.com/article...tionAspNet.asp
Nov 19 '05 #3
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.

"Larry David" <My***************@HealthyChoice.org> wrote in message
news:Nv********************@giganews.com...
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. :)

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Michael Rybak | last post: by
2 posts views Thread by Raquel | last post: by
2 posts views Thread by Rhino | last post: by
8 posts views Thread by Ankit Aneja | last post: by
2 posts views Thread by Delmar | last post: by
2 posts views Thread by J Huntley Palmer | last post: by
reply views Thread by khu84 | last post: by
2 posts views Thread by nsaffary | last post: by

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.