Solved

parameters  in clientvalidationfunction of customValidtor

Posted on 2009-05-12
2
983 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

635 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