Click here to Skip to main content
15,881,624 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created 2webforms login and signup. And later i have created masterpage. I have included these to pages in masterpage.But the problem is that my validations in javascript are not working on masterpage..It is not displaying alert messages like "fill firstname" etc. and when run this form without masterpage all the validations are working.what is the solution to this problem.
here is some code :
<script type="text/javascript">
function Validateform() {
var Firstname = document.getElementById("txtfirst").value;
if (Firstname == "First Name" || Firstname == "") {
alert("Firstname must be filled out");
return false;
}
else {
if (!Firstname.match(/^[a-zA-Z ]*$/) || Firstname.match(/ /) || Firstname.match(/@/) || Firstname.match(/^[#$%^&*()!]/)) {
alert("Invalid firstname");
return false;
}
}

   <asp:Button ID="signupbtn" runat="server" Text="Sign Up" onclick="signupbtn_Click" OnClientClick="return Validateform();" Class="button" />
Posted

When you implement Master Pages, the id of controls would be changed.

So, try like below...
JavaScript
document.getElementById('<%= txtfirst.ClientID %>');
 
Share this answer
 
Comments
Member 10523130 22-Jan-14 1:16am    
i tried that it is not entering data into database but it is not showing alert msgs for any of the empty text boxes.
Please debug and see what is happening.
Try

JavaScript
function Validateform() {
var Firstname = $get('<%= txtfirst.ClientID%>')
if (Firstname.value == "First Name" || Firstname.value == "") {
alert("Firstname must be filled out");
return false;
}
}
 
Share this answer
 
Comments
Member 10523130 22-Jan-14 1:16am    
i tried that it is not entering data into database but it is not showing alert msgs for any of the empty text boxes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900