Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

parameters  in clientvalidationfunction of customValidtor

Posted on 2009-05-12
2
Medium Priority
?
1,002 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses how to implement server side field validation and display customized error messages to the client.
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

916 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