Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language:
Expertise: Beginner
Feb 22, 2005

WEBINAR:

Live

Full Text Search: The Key to Better Natural Language Queries for NoSQL in Node.js


Date: 1/31/2018 @ 2 p.m. ET

Use CausesValidation to Prevent Unwanted Validation Checks

Validator controls automatically trigger validation checks for every postback—irrespective of whether you need validation or not. To prevent this, set CausesValidation="False" for the control for which you do not need validation. The code below will help illustrate:

<HTML>
	<HEAD>
		<title>WebForm1</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<asp:Label id="Label1" runat="server">Name</asp:Label>
			<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
			<asp:Button id="Button1" runat="server" Text="Save"></asp:Button>
			<asp:Button id="Button2" runat="server" Text="SomeOtherInfo"
CausesValidation="False"></asp:Button>
			<asp:RequiredFieldValidator id="RequiredFieldValidator1"
runat="server" ErrorMessage="User Name is required"
ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
			<asp:Label id="Label2" runat="server">Label</asp:Label>
		</form>
	</body>
</HTML>
If you simply drop two buttons on the form, clicking either button triggers validation by default. But because you don't need a validation check when you hit Button2, setting CausesValidation="False" in the Button2 control will do the trick.

Jaya Nehru Kumar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date