How do I hook up javascript to my CustomValidator control in .Net

前端 未结 3 1538
没有蜡笔的小新
没有蜡笔的小新 2021-01-28 12:30

I have created a CustomValidator control

public class MyValidator :CustomValidator, IScriptControl {}

and also created the equivalent client sc

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-28 13:14

    You can set the ClientValidationFunction property of the base class like this -

    base.ClientValidationFunction = "MyCustomJavascriptFunction";
    

    So, it will render it like this -

    MyValidator1.evaluationfunction = "MyCustomJavascriptFunction";
    

    You can do it from the control also by setting the same property.

    EDIT: You can do

    document.getElementById("<%= ValidatorId %>").evaluationfunction = "MyCustomJavascriptFunction";
    

提交回复
热议问题