How to get the 'controlToValidate' property on ClientValidationFunction?

前端 未结 3 644
遥遥无期
遥遥无期 2020-12-10 02:32

Lets say I have this code.





        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 02:53

    Not verified, just a hint:

    var v = document.getElementById('<%=CustomValidator1.FindControl(CustomValidator1.ControlToValidate).ClientID>%');
    

    of course you could simply do it like:

    var v = document.getElementById('<%=TextBox1.ClientID%>');
    

    if you know exactly what you're validating. The first method is good when the control to be validated is set dynamically and you don't know beforehand which one it will be.

    Also FindControl() might return null so you'd need to test for that too in order to avoid an exception.

    Hope this helps.

提交回复
热议问题