开发者

Remove onblur validation from ASP.net Control

I am wanting to remove the onblur event for a开发者_如何学Pythonsp.net validation, and only have the validation called when the button is clicked. Does anyone know how this can be accomplished?

Thanks


You can remove the validation events from given element

<body onload="removeValidationEvents();">

and the script:

    <script type="text/javascript">
    function removeValidationEvents() {
        document.getElementById('<%=yourTextbox.ClientID%>').onkeypress = null;
        document.getElementById('<%=yourTextbox.ClientID%>').onblur = null;
        document.getElementById('<%=yourTextbox.ClientID%>').onchange = null;
    }
    </script>

Note that ASP.NET uses different events depending on what control you're trying to validate (e.g. you may need to add onclick to the list above).

Also note that this is indeed a very ugly hack (as pointed in the comments below) and you should use it at your own peril.


you have to provide ValidationGroup property to button which is to be click, textbox and validation control. Same groupy name for all.

You then have to unset the onblur event of the control by right click it, choose properties, then go in event section by click flash button on top of the property window. then find onblur event and remove the calling event from its value cell.


In fact this is a built-in functionality which you can enable by set "Display" property on your validators:

<asp:RequiredFieldValidator runat="server" ID="val" Text="Please enter text" ErrorMessage="No text" ControlToValidate="txtText" Display="None" EnableClientScript="true" />

Now, during submit validation only 'No text' information will be displayed in SummaryValidator if you have one.

I assume that validation is still performed however you don't see the result. Is that what you meant?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜