开发者

Any way that I can set the error message for asp:CustomValidator?

Does anyone know do there have any way that I can set the error message for asp:CustomeValidator?

Example:

I have the following code to do the date validation:

<td><asp:TextBox runat="server" ID="activeDate" MaxLength="10" size="8"/>(DD-MM-YYYY)
    <br />
    <asp:CustomValidator id="CustomValidator2" runat="server" 
      ControlToValidate = "activeDate"
      ErrorMessage = "You must enter at least 8 characters!"
      ClientValidationFunction="validateLength" >
    </asp:CustomValidator>

Script code开发者_如何学运维:

<script type="text/javascript">
    function validateLength(oSrc, args) {
       args.IsValid = (args.Value.length >= 8);
    }
</script>

How can I manually set the error message in function validateLength instead hard code the error message in asp:CustomValidator (ErrorMessage = "You must enter at least 8 characters!") ??


You're kind of mixing metaphors with trying to update ASP.NET server-side settings from the client JavaScript. So you'd be better starting with something in Page_Load or your form events.

That said, you would find out by looking at the resultant HTML generate in a typical browser. Chances are it's a different element / property name than in the server-side code, but there is probably some HTML element you can easily update via JS on the client.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜