Jump to content

hi help on webpage validations


karthikc85

Recommended Posts

hi everybody,i need to validate a webpage with some textbox and button.compulsion is placed for user to write a text in textbox and if he clicks submit button with out text he must get an alert box.this should be done using javascript.in visualstudio 2005 (asp.net 2.0)assume that i have already placed an asp controls of textbox and button.any body please respond to me.thanks,karthik reddy chintaparthi.

Link to comment
Share on other sites

If you are using Visual Studio and ASP.NET, have you considered using the <asp:RequiredFieldValidator /> controls? They render javascript to the client so that you don't have to write it yourself.
hi jesh,thanks for responding to my query.what u said is right iam able to validate all my textboxes using validatorson the webpage.but my doubt all real time programmers suggest me to go for writing your own javascript for validating the fields.does it improve the efficiency of the webpage or it depends on requirements.please reply me.thanks,karthik.
Link to comment
Share on other sites

Oh, it's just easier. :) I don't know whether it's more efficient.In seriousness, though, .NET seems to have done a few things right and one of them is cross browser javascript validation that is generated by the .NET validation controls. However, with that being said, I have written my own validation scripts in certain situations and in these cases I've generally used the <asp:CustomValidator /> control.Check out this link: http://aspnet.4guysfromrolla.com/articles/073102-1.aspxBasically, the gist of it is that you create a javascript function similar to the following:

<script type="text/javascript">function validateForm(sender, args){	bool isValid = false;	// do the typical validation here.	// if it turns out that the form validates, 	// set isValid to true;	// then, simply set the value of the IsValid property	// of args to your isValid boolean.	args.IsValid = isValid;}</script>

Check out that article for more information. And look at W3 Schools tutorial if you need some advice on validating forms in general using javascript. In the tutorial, rather than returning true or false, you'll want to set the args.IsValid property to true or false.Good luck!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...