HOWTO化妆的RequiredFieldValidator更改CSS类的父股利 [英] Howto make RequiredFieldValidator change the css class of the parent div

查看:79
本文介绍了HOWTO化妆的RequiredFieldValidator更改CSS类的父股利的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了一个RequiredFieldValidator这样一个TextBox输入元素:

 < D​​IV>
    <标签>的名字< /标签>
    < ASP:的RequiredFieldValidator ID =RequiredFieldValidatorFirstname=服务器的ErrorMessage =必需的ControlToValidate =TextBoxFirstname>< / ASP:&的RequiredFieldValidator GT;
    < ASP:文本框ID =TextBoxFirstname=服务器>< / ASP:文本框>
< / DIV>

在文本框是上提交我想这个类的形式错误添加到父股利空的:

 < D​​IV CLASS =形式错误>
    <标签>的名字< /标签>
    < ASP:的RequiredFieldValidator ID =RequiredFieldValidatorFirstname=服务器的ErrorMessage =必需的ControlToValidate =TextBoxFirstname>< / ASP:&的RequiredFieldValidator GT;
    < ASP:文本框ID =TextBoxFirstname=服务器>< / ASP:文本框>
< / DIV>

这是可能的,如果是这样 - 我怎么办呢

解决方案

用的RequiredFieldValidator你不能添加自定义code。

您应该使用asp.net CustomValidator控件,写自己的自定义的验证javascript函数它设置类到div。

I have a TextBox input element that has a RequiredFieldValidator as such:

<div>
    <label>First name</label>
    <asp:RequiredFieldValidator ID="RequiredFieldValidatorFirstname" runat="server" ErrorMessage="Required" ControlToValidate="TextBoxFirstname"></asp:RequiredFieldValidator>
    <asp:TextBox ID="TextBoxFirstname" runat="server"></asp:TextBox>
</div>

When the TextBox is empty on submit I want to add the class 'form-error' to the parent Div:

<div class="form-error">
    <label>First name</label>
    <asp:RequiredFieldValidator ID="RequiredFieldValidatorFirstname" runat="server" ErrorMessage="Required" ControlToValidate="TextBoxFirstname"></asp:RequiredFieldValidator>
    <asp:TextBox ID="TextBoxFirstname" runat="server"></asp:TextBox>
</div>

Is this possible, and if so - how do I do it?

解决方案

with RequiredFieldValidator you can not add your custom code.

you should use asp.net customvalidator control, and write your own custom validation javascript function which sets the class to the div.

这篇关于HOWTO化妆的RequiredFieldValidator更改CSS类的父股利的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆