Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Server side controls

Are there any server side controls in the SDK that generate client-side
JavaScript for validation purposes?? Do I have to create my own?

I saw a sample of a serverside one (validates if the field is two digits)

<asp:RegularExpressionValidator id="RegExValidator"
ControlToValidate="CustomerId"
ValidationExpression="[0-9]{2}"
Display="Dynamic"
Font-Name="verdana" Font-Size="10"
runat=server>
Customer ID must be two numeric digits
</asp:RegularExpressionValidator>

but I'd rather have javascript generated so I can validate it "without the
click" so to speak.

Thanks,

Greg
[671 byte] By [Greg Huber] at [2007-11-9 16:23:51]
# 1 Re: Server side controls
I found an example off the microsoft web site, and modified it a tad bit.
I pasted it at the bottom of this message. It works great, generates the
javascript and does the checking client side. You can basically give it
whatever expression you want to validate in the validationexpression
attribute. That makes my life a TON easier.. not as much wasting time
flipping through a huge javascript reference!!

I think the Display="Dynamic" tag makes it do it client side..? I can't find
any real good documentation on this in the SDK or on the MS web site.
However, in case anyone else was wondering.. it's simple to do!

Thanks,
Greg

<%@ Page Language="vb" %>
<HTML>
<BODY>
<form runat=server>
<input type=password runat=server id=txtPWord>
<asp:RegularExpressionValidator runat=server display=dynamic
controltovalidate="txtPWord"
errormessage="Password must contain one of @#$%^&*/."
validationexpression=".*[@#$%^&*/].*" />
<asp:RegularExpressionValidator runat=server display=dynamic
controltovalidate="txtPWord"
errormessage="Password must be 4-12 nonblank characters."
validationexpression="[^\s]{4,12}" />
</form>
</HTML>
</BODY>

"Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
news:39a14bd3@news.dev-archive.com...
> Are there any server side controls in the SDK that generate client-side
> JavaScript for validation purposes?? Do I have to create my own?
>
> I saw a sample of a serverside one (validates if the field is two digits)
>
> <asp:RegularExpressionValidator id="RegExValidator"
> ControlToValidate="CustomerId"
> ValidationExpression="[0-9]{2}"
> Display="Dynamic"
> Font-Name="verdana" Font-Size="10"
> runat=server>
> Customer ID must be two numeric digits
> </asp:RegularExpressionValidator>
>
> but I'd rather have javascript generated so I can validate it "without the
> click" so to speak.
>
> Thanks,
>
> Greg
>
>
>
Greg Huber at 2007-11-11 23:26:25 >
# 2 Re: Server side controls
Try running the same script using a netscape 4.x browser, too.

You'll find that the valdiator controls are 'smart' enough to use
server-sdie validation for 'downlevel browsers that do not support DHTML
scripting.

This means you can use a single source code to support both types of
browsers.

The Quickstart examples also have a sample that shows you how to create your
own 'smart' control including the code that 'sniffs' the browser to
determine if the code should be client-side jScript or server-side code!

MCA
Mike Amundsen

Greg Huber <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
news:39a1636f$1@news.dev-archive.com...
> I found an example off the microsoft web site, and modified it a tad bit.
> I pasted it at the bottom of this message. It works great, generates the
> javascript and does the checking client side. You can basically give it
> whatever expression you want to validate in the validationexpression
> attribute. That makes my life a TON easier.. not as much wasting time
> flipping through a huge javascript reference!!
>
> I think the Display="Dynamic" tag makes it do it client side..? I can't
find
> any real good documentation on this in the SDK or on the MS web site.
> However, in case anyone else was wondering.. it's simple to do!
>
> Thanks,
> Greg
>
>
> <%@ Page Language="vb" %>
> <HTML>
> <BODY>
> <form runat=server>
> <input type=password runat=server id=txtPWord>
> <asp:RegularExpressionValidator runat=server display=dynamic
> controltovalidate="txtPWord"
> errormessage="Password must contain one of @#$%^&*/."
> validationexpression=".*[@#$%^&*/].*" />
> <asp:RegularExpressionValidator runat=server display=dynamic
> controltovalidate="txtPWord"
> errormessage="Password must be 4-12 nonblank characters."
> validationexpression="[^\s]{4,12}" />
> </form>
> </HTML>
> </BODY>
>
>
>
>
> "Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
> news:39a14bd3@news.dev-archive.com...
> > Are there any server side controls in the SDK that generate client-side
> > JavaScript for validation purposes?? Do I have to create my own?
> >
> > I saw a sample of a serverside one (validates if the field is two
digits)
> >
> > <asp:RegularExpressionValidator id="RegExValidator"
> > ControlToValidate="CustomerId"
> > ValidationExpression="[0-9]{2}"
> > Display="Dynamic"
> > Font-Name="verdana" Font-Size="10"
> > runat=server>
> > Customer ID must be two numeric digits
> > </asp:RegularExpressionValidator>
> >
> > but I'd rather have javascript generated so I can validate it "without
the
> > click" so to speak.
> >
> > Thanks,
> >
> > Greg
> >
> >
> >
>
>
Mike Amundsen at 2007-11-11 23:27:22 >
# 3 Re: Server side controls
Actually, the display=dynamic is supposed to not reserve space for the error
text until it is displayed (potentially changing the layout) whereas display=static
will allocate the space to start with, and just display when the validation
fails.

There was something on turning on/off the client side validation... but
wasn't important to me so I don't remember.

Steve
Steve at 2007-11-11 23:28:26 >
# 4 Re: Server side controls
Hi, Greg

I think all controls on the web are bad ideas. If someone wants to write
an application and is not prepared enough even to do the most rudimentary
validation such as writing javascript, then it is not justifiable to get
that someone to write the programs. One can always write some standard javascript
such as email validation, validating null spaces, etc and include that as
a .js file so that all validation becomes extremely easy and re-usable over
and over again. If you are a non-programmer, please stop complaining about
writing code ... Let the programmers talk about writing more real code ...

"Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote:
>Are there any server side controls in the SDK that generate client-side
>JavaScript for validation purposes?? Do I have to create my own?
>
>I saw a sample of a serverside one (validates if the field is two digits)
>
><asp:RegularExpressionValidator id="RegExValidator"
> ControlToValidate="CustomerId"
> ValidationExpression="[0-9]{2}"
> Display="Dynamic"
> Font-Name="verdana" Font-Size="10"
> runat=server>
> Customer ID must be two numeric digits
> </asp:RegularExpressionValidator>
>
>but I'd rather have javascript generated so I can validate it "without the
>click" so to speak.
>
>Thanks,
>
>Greg
>
>
>
David Chah at 2007-11-11 23:29:25 >
# 5 Re: Server side controls
BTW that is all the server side controls do. They are controls in name and
encapsulation only.

"David Chah" <davidchah@nviss.com> wrote in message
news:39afbbeb$1@news.dev-archive.com...
>
> Hi, Greg
>
> I think all controls on the web are bad ideas. If someone wants to write
> an application and is not prepared enough even to do the most rudimentary
> validation such as writing javascript, then it is not justifiable to get
> that someone to write the programs. One can always write some standard
javascript
> such as email validation, validating null spaces, etc and include that as
> a .js file so that all validation becomes extremely easy and re-usable
over
> and over again. If you are a non-programmer, please stop complaining about
> writing code ... Let the programmers talk about writing more real code ...
>
> "Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote:
> >Are there any server side controls in the SDK that generate client-side
> >JavaScript for validation purposes?? Do I have to create my own?
> >
> >I saw a sample of a serverside one (validates if the field is two digits)
> >
> ><asp:RegularExpressionValidator id="RegExValidator"
> > ControlToValidate="CustomerId"
> > ValidationExpression="[0-9]{2}"
> > Display="Dynamic"
> > Font-Name="verdana" Font-Size="10"
> > runat=server>
> > Customer ID must be two numeric digits
> > </asp:RegularExpressionValidator>
> >
> >but I'd rather have javascript generated so I can validate it "without
the
> >click" so to speak.
> >
> >Thanks,
> >
> >Greg
> >
> >
> >
>
Chris Kinsman at 2007-11-11 23:30:24 >
# 6 Re: Server side controls
Can you post such an example of such .js file here please? And briefly describe
how it works?

would be much appreciated

Tom

"David Chah" <davidchah@nviss.com> wrote:
>
>Hi, Greg
>
>I think all controls on the web are bad ideas. If someone wants to write
>an application and is not prepared enough even to do the most rudimentary
>validation such as writing javascript, then it is not justifiable to get
>that someone to write the programs. One can always write some standard javascript
>such as email validation, validating null spaces, etc and include that as
>a .js file so that all validation becomes extremely easy and re-usable over
>and over again. If you are a non-programmer, please stop complaining about
>writing code ... Let the programmers talk about writing more real code ...
>
TTocek at 2007-11-11 23:31:29 >
# 7 Re: Server side controls
The following statement:

> If someone wants to write
> an application and is not prepared enough even to do the most rudimentary
> validation such as writing javascript, then it is not justifiable to get
> that someone to write the programs.

in the same vein of idea could be: (from a person who likes to store
databases in a file rather than the new fangled database engines)

"if someone wants to write an database and is not prepared enough even
to do the most rudimentary data manipulation such as creating a
file and storing the data there, then it is not justifiable to get that
someone to write programs to store data"

The point is that these tools, objects, and libraries are all to prevent
you from doing that simplistic coding to give you more time
to get to the "heart" of the application. They allow faster
development time and allow changes to be made more easily.

Of course.. they are all optional if you don't want to use them,
you can still write your own simplistic java snippets just like
always.
Thomas Kadlec at 2007-11-11 23:32:29 >
# 8 Re: Server side controls
it's
'write a database' NOT 'write an database'

Thomas, you make a very good point.
There are many ways to program a certain function and to solve a certain
problem.

The simpliest way is not always the 'BEST' way.

"Thomas Kadlec" <kadlect@hotmail.com> wrote:
>The following statement:
>
>> If someone wants to write
>> an application and is not prepared enough even to do the most rudimentary
>> validation such as writing javascript, then it is not justifiable to
get
>> that someone to write the programs.
>
>in the same vein of idea could be: (from a person who likes to store
>databases in a file rather than the new fangled database engines)
>
>"if someone wants to write an database and is not prepared enough even
>to do the most rudimentary data manipulation such as creating a
>file and storing the data there, then it is not justifiable to get that
>someone to write programs to store data"
>
>The point is that these tools, objects, and libraries are all to prevent
>you from doing that simplistic coding to give you more time
>to get to the "heart" of the application. They allow faster
>development time and allow changes to be made more easily.
>
>Of course.. they are all optional if you don't want to use them,
>you can still write your own simplistic java snippets just like
>always.
>
>
kai0_tika kai0_tika at 2007-11-11 23:33:27 >