Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

ASP.net Client Side Validator problem

Options
  • 02-10-2008 11:23am
    #1
    Registered Users Posts: 2,791 ✭✭✭


    Hi,

    I have a Modal Popup displaying properties that can be edited by the user. My problem is that if a user triggers error validation and clicks the close button, when they open a different property then the OK button is disabled because of the previous validation error.

    E.g

    1)User clicks 'Cost' and a Modal Popup displays the Cost properties.

    2)User enters invalid Data. Validation message is shown. User clicks Modal Popup Close Button.

    3)User now clicks 'Date' and a Modal Popup displays the Date properties. Everything appears normal - no validation message is shown.

    4)User tries to click OK button but nothing happens.

    This only happens when validation has previously been triggered. The properties themselves are added dynamically to a placeholder. The very first thing I do is clear that placeholder of any controls - so this should clear the validator as well shouldnt it? :confused:

    Would appreciate any suggestions!

    Thanks
    John


Comments

  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    The validator objects are held against the page. Once one of the is marked as invalid, it will stay that way if you cancel the modal dialog. There's a couple of ways you can try clear this out.

    I think calling this.Validate() forces every validator on the page to revalidate. I'm not sure how this would work with dynamic controls that no longer exist.

    You could iterate through this.Validators and set each isValid = true. This will of course revalidate any other controls on your page which should be invalidated.

    You could try to find the specific validators with this.GetValidators and set isValid = true, you may need to create the validators specifically as part of a group to find the correct ones.


    edit: Oh, and if you already have a reference to the validator then just set it's isValid = true.


  • Registered Users Posts: 4,077 ✭✭✭muckwarrior


    Would splitting them into validation groups not work?


  • Registered Users Posts: 2,791 ✭✭✭John_Mc


    stevenmu wrote: »
    The validator objects are held against the page. Once one of the is marked as invalid, it will stay that way if you cancel the modal dialog. There's a couple of ways you can try clear this out.

    I think calling this.Validate() forces every validator on the page to revalidate. I'm not sure how this would work with dynamic controls that no longer exist.

    You could iterate through this.Validators and set each isValid = true. This will of course revalidate any other controls on your page which should be invalidated.

    You could try to find the specific validators with this.GetValidators and set isValid = true, you may need to create the validators specifically as part of a group to find the correct ones.


    edit: Oh, and if you already have a reference to the validator then just set it's isValid = true.

    Hi Steven,

    Thanks for your reply. My problem is that all of this is taking place on the client side, so I have no server side events to iterate through the controls....


  • Registered Users Posts: 2,791 ✭✭✭John_Mc


    Would splitting them into validation groups not work?

    No because all of them are based on a Modal Popup Base class so use the same OK & Cancel buttons.

    It's a very messy problem :(


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    There is the ValidatorEnable javascript method for asp.net controls, it allows you to enable and disable on the clientside as you go. Perhaps you could use that?


  • Advertisement
  • Registered Users Posts: 2,791 ✭✭✭John_Mc


    Evil Phil wrote: »
    There is the ValidatorEnable javascript method for asp.net controls, it allows you to enable and disable on the clientside as you go. Perhaps you could use that?

    Thanks for the suggestion Phil, however I got around the problem by removing the invalid text from the textbox in a server side event. Then I just hid the modal popup.


Advertisement