Wrox Programmer Forums
|
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
 
Old September 18th, 2010, 03:02 PM
Authorized User
 
Join Date: Sep 2010
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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..
 
Old September 19th, 2010, 06:56 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 19th, 2010, 11:23 AM
Authorized User
 
Join Date: Sep 2010
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
 
Old September 19th, 2010, 12:45 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 19th, 2010, 12:52 PM
Authorized User
 
Join Date: Sep 2010
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 !!!!
 
Old September 19th, 2010, 01:06 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 19th, 2010, 01:49 PM
Authorized User
 
Join Date: Sep 2010
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ahaa, thanks , i thought the star will disappear as soon as i fill data in the text box without clicking the button :) thanks :)
 
Old September 19th, 2010, 02:50 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Not with this CustomValidator. It does work for the other validators in the page, such as the RequiredFieldValidator.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript. Magxtopher Javascript 2 April 1st, 2014 09:27 PM
Javascript yogeshjpawar Javascript 6 April 22nd, 2009 06:40 AM
stop current javascript function using javascript sakthi Javascript 3 June 2nd, 2008 03:30 PM
JavaScript sumith ASP.NET 2.0 Basics 2 October 2nd, 2007 09:59 PM
"text/javascript" and "javascript" rupen Javascript 1 June 24th, 2005 07:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.