Solved

parameters  in clientvalidationfunction of customValidtor

Posted on 2009-05-12
2
939 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

746 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

12 Experts available now in Live!

Get 1:1 Help Now