Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a registration form in asp. net 3.5. I have written a javascript to perform validations on form elements. On form submit event i have called to javascript functon. When i click on submit button its working properly. But when i click on reset button then also the form is being validating. So how should i write code to not validate form when i click on REset button. Please help me...
Posted
Comments
Uday P.Singh 10-Oct-11 1:31am    
post your code which you have written on reset button?

create another javascript function for the reset to clear all the fields and in onclientclick call that function ..

C#
function clear()
{

document.getElementById('<%=txtbox1.ClientID%>').value="";
document.getElementById('<%=txtbox2.ClientID%>').value="";
document.getElementById('<%=txtbox3.ClientID%>').value="";        
document.getElementById('<%=txtbox4.ClientID%>').value="";
}


this is reset button in this way you can call
 <asp:imagebutton id="imgbtnReset" runat="server" imageurl="~/images/reset_btn.gif" xmlns:asp="#unknown">
                                                                            OnClick="imgbtnReset_Click" OnClientClick="javascript:return clear();" />
</asp:imagebutton>
 
Share this answer
 
You need to set the CausesValidation property of the button false. Default value for this property is true.

Example :
ASP.NET
<asp:button causesvalidation="TRUE|FALSE" runat="server" xmlns:asp="#unknown" />


For more information on this property refer :
1. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.causesvalidation.aspx[^]
2. http://www.w3schools.com/ASPNET/prop_webcontrol_button_causesvalidation.asp[^]

Hope this helps.
All the best.
 
Share this answer
 
Instead of OnSubmit, you can use OnClick event.
JavaScript
<button onclick="document.getElementById('field2')">Submit here</button>
 
Share this answer
 

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