Click to See Complete Forum and Search --> : asp.net + javascript validation


whathappened9
01-08-2007, 05:42 PM
Hello,

I have a subscribtion page which validates use input using javaScript, if valid info should be sent to server and saved. Until this point it was validating the user input

// this is sub.aspx
<input id="Button1" type="button" value="Submit" runat="server" onclick="validateForm()" />

/// in sub.aspx.cs

Button1.Attributes.Add("onclick", "return validateForm()");



The problem is after I defined Button1_ServerClick in my sub.aspx.cs page to get the info and save it to database. now even the client side validation is not working. could some one please guide how to do this the right way.

sirpelidor
01-12-2007, 05:24 PM
in most cases, i prefer to use validators (http://www.codersource.net/asp_net_validation_controls.aspx).

You'll find a lot of built-in / custom validators examples through google.

cemaksoy
01-13-2007, 10:00 AM
if your form validation is not valid, your javascript function must returns false
Are you sure your code like this ? If you are sure check the syntax of your js function.Firefox javascript error console helps you.You can find any errors in your js.


<script type="text/javascript">

function validateForm()
{
if(pageValid == true) // Your validation should be here
{
return true;
}
else
{
return false;
}

}

</script>