Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Validator question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
HockeyFan - 01 Aug 2007 15:04 GMT
I've got a dropdownlist that upon user selection, I have a javascript
function that is run.  This function, depending upon which selection
from the dropdown, turns one small section visible and enables its
validator, and turns another similar section off and turns off its
validator.  I run this function also on page load, so that it'll run
based on current settings from the database.  It works fine, except
that if the user changes the selection, then the validator displays
the error message (because the text box is empty).  The thing is, I
set CausesValidation to false on the dropdownlist, so I'm not sure why
this is happening.

Any ideas:

function ddlLoanSystem_Changed()
{
   var ddlLoanSystem = document.getElementById('ddlLoanSystem');
   var valtxtACCustomerNumber =
document.getElementById('rptBorrower_ctl00_valtxtACCustomerNumber');
   var valtxtWCCustomerNumber =
document.getElementById('rptBorrower_ctl00_valtxtWCCustomerNumber');
   var spanACCustomerNumber =
document.getElementById('rptBorrower_ctl00_spanACCustomerNumber');
   var spanWCCustomerNumber =
document.getElementById('rptBorrower_ctl00_spanWCCustomerNumber');

   switch(ddlLoanSystem.options[ddlLoanSystem.selectedIndex].value)
   {
       case 'ALS':
           spanWCCustomerNumber.style.display = 'none';
           ValidatorEnable(valtxtWCCustomerNumber, false);
           spanACCustomerNumber.style.display = '';
           ValidatorEnable(valtxtACCustomerNumber, true);
           break;
       case 'ACBS':
           spanWCCustomerNumber.style.display = '';
           ValidatorEnable(valtxtWCCustomerNumber, true);
           spanACCustomerNumber.style.display = 'none';
           ValidatorEnable(valtxtACCustomerNumber, false);
           break;
   }
}
Teemu Keiski - 01 Aug 2007 15:43 GMT
CausesValidation has impact only on Buttons - in ASP.NET 2.0 controls which
implement IButtonControl interface. See the rendered HTML what's on onchange
attribute of the SELECT element, it should give clue what's going on

Signature

Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

> I've got a dropdownlist that upon user selection, I have a javascript
> function that is run.  This function, depending upon which selection
[quoted text clipped - 37 lines]
>    }
> }
Peter Bucher [MVP] - 01 Aug 2007 17:12 GMT
Hello les

> function ddlLoanSystem_Changed()
> {
>    var ddlLoanSystem = document.getElementById('ddlLoanSystem');
>    var valtxtACCustomerNumber =
> document.getElementById('rptBorrower_ctl00_valtxtACCustomerNumber');
>    var valtxtWCCustomerNumber =
Use <Control>.ClientID instead of hard coded IDs.
IDs can change! :-)

Signature

Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET

HockeyFan - 01 Aug 2007 18:31 GMT
> Use <Control>.ClientID instead of hard coded IDs.
> IDs can change! :-)

In this case, I can't really pass a control id.  The reason is that
this routine, in addition to be run when the dropdown is selected, is
also run at page load.  At page load, I have no way of really getting
the control from the repeater, other than I know that it's the control
in the first item of the repeater.  If I had a way of accessing the
repeater from javascript, traversing it's contents and gettnig the
control, I would.  However, to my knowledge when the page is actually
rendered, there is no repeater, and hence, no way of being able to do
that.
Suggestions are welcome though.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.