如何为ASP.NET中的重置按钮编写代码 [英] How to write code for reset button in asp .net
问题描述
我已经在asp中创建了一个注册表.净3.5.我写了一个JavaScript来对表单元素执行验证.在表单提交事件中,我已经调用了javascript functon.当我单击提交按钮时,其工作正常.但是,当我单击重置"按钮时,表格也正在验证中.因此,当我单击重置"按钮时,我应该如何编写代码以不验证表单.请帮助我...
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...
推荐答案
创建另一个JavaScript函数以进行重置以清除所有字段,并在onclientclick中调用该函数..
create another javascript function for the reset to clear all the fields and in onclientclick call that function ..
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>
您需要将按钮的CausesValidation
属性设置为false.此属性的Default value
是true
.
示例:
You need to set theCausesValidation
property of the button false.Default value
for this property istrue
.
Example :
<asp:button causesvalidation="TRUE|FALSE" runat="server" xmlns:asp="#unknown" />
有关此属性的更多信息,请参见:
1. http://msdn.microsoft.com/zh-我们/library/system.web.ui.webcontrols.button.causesvalidation.aspx [ http://www.w3schools.com/ASPNET/prop_webcontrol_button_causesvalidation.asp [
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.
您可以使用OnClick事件代替OnSubmit.
Instead of OnSubmit, you can use OnClick event.
<button onclick="document.getElementById('field2')">Submit here</button>
这篇关于如何为ASP.NET中的重置按钮编写代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!