Sunday, July 26, 2009

I want to validate fields of my webpage from client side. in ASP.Net, C#.Net, and Javascript environment. How?

I want to validate invalid information by using Javascript function.... just above the line of database insert query..





I have done using C# but it became server side validation and takes longtime to validate. I want to validate fields from client side.....





Please tell me idea How can I do that....


Thanks in advance

I want to validate fields of my webpage from client side. in ASP.Net, C#.Net, and Javascript environment. How?
http://www.w3schools.com/js/js_form_vali...





Above is an article on simple JavaScript form validation, but it has enough information to get you headed in the right direction. The only somewhat difficult part when doing it with .NET can be making sure that the JavaScript has the right element IDs. The easiest way is to write out a block of JavaScript from the server-side that declares the names of your fields:





ltJsDecControl.Text = "var nameField = '" + txtName.ClientID + "'";





Then in your JavaScript validation function, simply reference nameField instead of trying to call it by name or ID.





Keep in mind that you should always validate on both server- and client-side. Client-side validation can be easily bypassed (as simple as just turning off JavaScript), at which point you could be vulnerable to bad data at best, or at worst a SQL injection attack.


No comments:

Post a Comment