Solved

parameters  in clientvalidationfunction of customValidtor

Posted on 2009-05-12
2
946 Views
Last Modified: 2012-05-06
There are two parameters in clientvalidationfunction of customValidtor: source, arguments.
On Internet, I can find some examples on how to use arguments. But I did not find any samples on how to use source. Could someone please give some samples about source parameter in clientvalidationfunction?
Can I use source.getAttributes["abc"] that I set in Page_Load  (control.Attributes.Add("abc","....")?
0
Comment
Question by:treehouse2008
2 Comments
 
LVL 11

Accepted Solution

by:
Muhammad Ousama Ghazali earned 500 total points
ID: 24369980
1. The source parameter mostly points to the validator itself.
2. It is the args which has importance most of the time. See the code snippet attached on how to use its IsValid property. IsValid is case sensitive and is intentional and should never be written as isValid in this context.
3. For ClientValidationFunction property set it by writing only the JavaScript name without any paranthesis () or arguments. In our example, it is isPasswordsMatch.
Although it is bit old but this would give an insight on Validations especially the Custom Validations in ASP.NET: http://msdn.microsoft.com/en-us/library/aa479045.aspx

//THE ACTUAL JAVASCRIPT

function isPasswordsMatch(source, args)

{

	var password = document.getElementById("txtPassword.ClientID");

	var confirmPassword = document.getElementById("txtConfirmPassword.ClientID");

	

	if (password && confirmPassword)

	{

		if (password.value != confirmPassword.value)

			args.IsValid = false;

		else

			args.IsValid = true;

	}

	else

		args.IsValid = false;

}
 

'BUT THIS IS EMITTED FROM Page_PreRender event so to include appropriate ClientID of the two controls
 

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
 

	Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "validatePasswordsMatch", "function isPasswordsMatch(source, args){var password = document.getElementById(""" & txtPassword.ClientID & """);var confirmPassword = document.getElementById(""" & txtConfirmPassword.ClientID & """);if (password && confirmPassword) {if (password.value != confirmPassword.value)args.IsValid = false;else args.IsValid = true;}else args.IsValid = false;}", True)
 

End Sub

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now