Check client side validation

It’s possible to check whether a certain validation group is valid via Javascript code by using the function

Page_ClientValidate()
<script type="text/javascript">

	function disableButton(btn, groupName) {
		if (Page_ClientValidate(groupName)) { //check validation
			btn.disabled = true;
	};

</script>

<asp:TextBox ID="TextBox1" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
	ControlToValidate="TextBox1" ValidationGroup="GroupA" />

<asp:TextBox ID="TextBox2" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
	ControlToValidate="TextBox2" ValidationGroup="GroupB" />

<p />
<asp:Button ID="Button1" runat="server" Text="Button1"
	OnClientClick="disableButton(this, 'GroupA')" onclick="Button1_Click" />
Advertisements

One thought on “Check client side validation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s