开发者

Validation controls are not validating on enabling on client side using JavaScript

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 okay 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].Enable开发者_如何学JAVAd = true;
            }
        }

    }
</script>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜