I’m developing an intranet desktop application and most of functionality requires a web interface to go along with it. The desktop part for the first iteration is pretty much complete and now I have to do it in WebForms. I haven’t touched WebForms in over a year and am wondering…
If I have a form with some textboxes, I realize I can code validation using javascript and whatnot but is there a way that I can do it like I can in WinForms? WinForms textboxes have a Validating method that is called when the user leaves the texbox. On the desktop app I have it rigged up to set the class instance property which has validation in the setting of the property. Is there a way I can do the same in WebForms or must I write it all out again on the client side? ASP TextBoxes have a textchanged method, but I don’t see validating. I’m thinking you guys are going to say I have to write it all out again client-side, but here’s to hoping.
You don’t have to do it from scratch. Asp.Net has several built-in validators to assist with data types, range, comparison between fields, required fields, and even with a summary of the errors. See this link for more info
You can also use your own javascript with this validation model using the CustomValidator control.
w3schools.com has a really nice tutorial here
Edited: Avoiding postbacks
You can wrap your TextBox with an UpdatePanel in order to use Ajax or if you want to make it more efficient you could use jQuery to call a WebMethod and set the object. Example:
On the client side: