 |
BOOK: Beginning ASP.NET 4 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

September 18th, 2010, 03:02 PM
|
|
Authorized User
|
|
Join Date: Sep 2010
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Why do we need javascript
i have tried the try it out for validation using custom validator.
i ran the code and it worked even when i didn't put the javascript code, and the red asterisk appeared when other red asterisks appeared too, means it appeared on the client side..
|
|

September 19th, 2010, 06:56 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Take a look at page 300, under the heading "A Warning on Client-Side Validation". The JavaScript executes at the client, giving users immediate feedback without the need for a postback.
Cheers,
Imar
|
|

September 19th, 2010, 11:23 AM
|
|
Authorized User
|
|
Join Date: Sep 2010
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hello, i tried the javascript as mentioned in the book , and it renders in the browser without errors, but when i fill any on the phone numbers text boxes, the red start (*) is not removed immediately unless i post back the page to the server which means that the java script is not working on the page.
here is my code :
Code:
<script type="text/javascript">
function ValidatePhoneNumbers(source, args) {
var phoneHome = document.getElementById('<%= PhoneHome.ClientID %>');
var phoneBusiness = document.getElementById('<%= PhoneBusiness.ClientID %>');
if (phoneHome.value != '' || phoneBusiness.value != '') {
args.IsValid = true;
}
else {
args.IsValid = false;
}
}
and for the custom validation, i made the client validation function property = ValidatePhoneNumbers, should i change the control to validate?
|
|

September 19th, 2010, 12:45 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
This is by design. Since the control is not directly associated with an HTML form control (it uses multiple controls in the validation function), validation is carried out when you click a submit button.
Cheers,
Imar
|
|

September 19th, 2010, 12:52 PM
|
|
Authorized User
|
|
Join Date: Sep 2010
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
so when i put the javascript and when i removed it, it has the same behavior, both cases i need to post back again to get rid of the red star? why do i need it !!!!
|
|

September 19th, 2010, 01:06 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You don't *need* it, but as I explained in the book, it serves as a courtesy to the user so they don't have to postback, but get an immediate respons.
If you're seeing a postback when you leave both fields empty and click the button, something is wrong. Can you check if it really posts back (you should see the browser's progress bar) and if it does, post the full code for the entire control?
Cheers,
Imar
|
|

September 19th, 2010, 01:49 PM
|
|
Authorized User
|
|
Join Date: Sep 2010
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ahaa, thanks , i thought the star will disappear as soon as i fill data in the text box without clicking the button :) thanks :)
|
|

September 19th, 2010, 02:50 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Not with this CustomValidator. It does work for the other validators in the page, such as the RequiredFieldValidator.
Cheers,
Imar
|
|
 |
|