Validator question

Discussion in 'ASP .Net' started by HockeyFan, Aug 1, 2007.

  1. HockeyFan

    HockeyFan Guest

    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;
    }
    }
    HockeyFan, Aug 1, 2007
    #1
    1. Advertising

  2. HockeyFan

    Teemu Keiski Guest

    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

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


    "HockeyFan" <> wrote in message
    news:...
    > 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, Aug 1, 2007
    #2
    1. Advertising

  3. 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! :)

    --
    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
    Peter Bucher [MVP], Aug 1, 2007
    #3
  4. HockeyFan

    HockeyFan Guest

    >
    > 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.
    HockeyFan, Aug 1, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephan Bour

    Regex validator question

    Stephan Bour, Oct 28, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    340
    Stephan Bour
    Oct 28, 2003
  2. TN Bella

    Validator question

    TN Bella, Jun 15, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    321
    TN Bella
    Jun 15, 2004
  3. Ken Varn
    Replies:
    1
    Views:
    2,639
    Peter Blum
    Nov 2, 2004
  4. MattB

    Custom Validator newbie question

    MattB, Nov 23, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,948
    Teemu Keiski
    Nov 23, 2004
  5. Replies:
    4
    Views:
    896
    Richter~9.6
    Feb 13, 2007
Loading...

Share This Page