Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1008
  • Last Modified:

parameters in clientvalidationfunction of customValidtor

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
treehouse2008
Asked:
treehouse2008
1 Solution
 
Muhammad Ousama GhazaliSolution Analyst & ArchitectCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now