views:

18

answers:

1

Hi,

As per requirement I disabled all validation controls in page on PageLoad event in server side.

On clicking submit button I want to activate them and validate the page and if the page is ok submit other wise not.

I am able to enable all validaters but one thing that I am unable to understand is that they do not validate the page. I set alerts and check they are being enabled but they do not validate the page and let the page submit.

I am sorry I couldn't get where I am wrong, may be there need to call some validation method as well or I should prevent default behavior of button. please guide me.

Below is my script:

<script type="text/javascript">
    function NextClicked() {

        var _ddlStatus = document.getElementById("<%=ddlEmpStatus.ClientID%>");
        var _selectedIndex = _ddlStatus.selectedIndex;

        if (_selectedIndex == 0) {
            alert("Nothing selected");
        }<br/>
        else<br/>
            if (_selectedIndex == 1) {
            for (i = 0; i < Page_Validators.length; i++) {
                Page_Validators[i].Enabled = true;
            }
        }

    }
</script>

thanks in anticipation.

A: 

Hey,

From the server, you have to have them enabled before the button click; otherwise, I think you need to loop through the server-side collection and enable them, plus call their validate() method explicitly.

Or, you can also try the client-side validatorenable method (http://forums.asp.net/t/1175267.aspx) to enable them.

If you disable by setting Enabled = false from the server, you may have issues even using the client-side API altogether. Not sure about that though, just know that can be an issue with other controls.

HTH.

Brian
On post back I am looping through these validaters and than calling Validate() methed to do server side validation. But issue is on client side.Please advise
haansi
Try the validatorEnable() method in the link; check the client-side API section of this: http://msdn.microsoft.com/en-us/library/aa479045.aspx however, I don't know that this works if you Set Enabled="false" on the server; you may need to let it enabled on the server, and disable on the load of the page in the client... not 100% sure about that...
Brian