473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 1581
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
2
by: Raquel | last post by:
How do I know whether the 'runtime client' and the 'application development client' are installed on my machine? When I issue the command "db2licm -l", it gives the following output: Product...
2
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info...
0
by: Harley | last post by:
Hello, I am just learning the tcp/ip functions etc under vb.net so please look over me if this is obviouse. I have been all over looking into any functions that I didn't totaly understand and...
8
by: Ankit Aneja | last post by:
i am doing here some some socket-client work in C# windows service it is working fine for multiple clients now i want to limit these multiple clients to 25 for example i want that when service...
2
by: Delmar | last post by:
I need to build Web Application that will generate a client to execute some operations. Each client has running silent application. Maybe somebody can advice me what can I do ? Thank you.
2
by: J Huntley Palmer | last post by:
I am having a horrific time integrating uw-imap's c-client for imap support in php. The problem is a whole bunch of "Text relocation remains referenced against symbol" errors during linking....
0
by: khu84 | last post by:
Here is client server very simple code, seems to work with telnet but with with web client code gives blank output. Following is the server code:- <?php function...
2
by: nsaffary | last post by:
hi I hava a client/server program that run correctly when i run it in one computer(local) but when I run client on a one computer and run server run on another, connection does not stablish.(I set...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.