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

前端 未结 3 1579
没有蜡笔的小新
没有蜡笔的小新 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:03

    I've answered this myself as the other answer didn't quite achieve exactly what I wanted. I ended up using.

    public class MyValidator : BaseValidator, IScriptControl  {
    
      protected override void AddAttributesToRender(HtmlTextWriter writer) {
        base.AddAttributesToRender(writer);
        Page.ClientScript.RegisterExpandoAttribute(this.ClientID, "evaluationfunction", "MyJavascriptFunction");
      }
    
    }
    

    Which will cause the control to generate:

    MyValidator1.evaluationfunction = "MyJavascriptFunction";
    

提交回复
热议问题