p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 4 General Discussion (http://p2p.wrox.com/forumdisplay.php?f=561)
-   -   validation class like css class (http://p2p.wrox.com/showthread.php?t=88367)

sophia September 2nd, 2012 04:16 AM

validation class like css class
Hello all,

In web forms we need to use validation controls at many stages, and in a complete website we have many pages which need validations.

But at every page we have to use those validation controls with full definition. So isn't there a way to use validation controls as we do with css classes, just define once and use anywhere.

for ex, for textbox and ragular expression I want to write code like this

<asp:TextBox ID="TextBox1" runat="server" ValidationClass="Regular(Email)"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" ValidationClass="Regular(ContactNo)"></asp:TextBox>
if it is possible anyhow.

Please tell me if this/or similar method is possible.

Many thanks

Imar September 2nd, 2012 06:33 AM

You could build your own custom controls. In this case, you would need a composite control that contains a TextBox and a RegularExpressionValidator. For more details: http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx

Not necessarily an easy thing to do, but it could be worth it if you have the need for validatable TextBox controls as you described.



sophia September 2nd, 2012 09:26 AM

Thanks Imar,
I will dare to do that, and update when I would do.

All times are GMT -4. The time now is 11:38 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.