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