简体   繁体   English

用户控件的必需字段验证器不起作用

[英]Required field validator for User control not working

Hi I have created user control for re-sizable text box. 嗨,我已经为可调整大小的文本框创建了用户控件。

<asp:Panel ID="PanelText" runat="server" CssClass="frameText">
<asp:TextBox runat="server" ID="TextBoxResizable" CssClass="noborder" Width="100%"
    Height="100%" TextMode="MultiLine">
</asp:TextBox>
</asp:Panel>
<cc1:ResizableControlExtender ID="ResizableTextBoxExtender" runat="server" TargetControlID="PanelText"
ResizableCssClass="resizingText" HandleCssClass="handleText" OnClientResizing="OnClientResizeText" />

And have created Validator property for this control like: 并为此控件创建了Validator属性,例如:

[ValidationProperty("Text")]
 public partial class ResizableTextBoxControl : System.Web.UI.UserControl
{ public string Validator
{
    get { return this.TextBoxResizable.Text; }
} 
protected void Page_Load(object sender, EventArgs e)
 {

 }
}

In aspx page I am using this control like: 在aspx页面中,我正在使用以下控件:

<uc1:ResizableTextBoxControl ID="tbDescription" MinimumHeight="50" MinimumWidth="100"
 MaximumHeight="300" MaximumWidth="400" runat="server" onKeyPress="javascript:Count(this,1500);" onKeyUp="javascript:Count(this,1500);" ValidationGroup="vgSubmit" ></uc1:ResizableTextBoxControl>

 <asp:RequiredFieldValidator ID="rfvDescription" runat="server" controlToValidate="tbDescription" ValidationGroup="vgSubmit" ErrorMessage="Description" Text="*" ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>

When I click on submit, "tbDescription" does not appear to be mandatory. 当我单击提交时,“ tbDescription”似乎不是必需的。 What can be wrong with the code? 代码有什么问题?

EDIT 编辑

Ok...I got what was the problem, one control was hidden, and required field validator for that control was not disabled, I did it using jquery and now everything is fine except asterics.. I dont understand why asterics are not visible.. 好吧...我明白了问题所在,隐藏了一个控件,并且未禁用该控件所需的字段验证器,我使用jquery进行了操作,现在除星号外一切都很好。.我不明白为什么星号不可见。 。

try placing your validator to your controlle especially if you just try to validate one textbox 尝试将验证器放到您的控件中,特别是如果您只是尝试验证一个文本框

   <asp:Panel ID="PanelText" runat="server" CssClass="frameText">
<asp:TextBox runat="server" ID="TextBoxResizable" CssClass="noborder" Width="100%"
    Height="100%" TextMode="MultiLine">

    </asp:TextBox>
     <asp:RequiredFieldValidator 
ID="rfvDescription" runat="server" controlToValidate="TextBoxResizable"
 ValidationGroup="vgSubmit" 
ErrorMessage="Description" Text="*" 
ForeColor="Red" SetFocusOnError="True">

</asp:RequiredFieldValidator
    </asp:Panel>
    <cc1:ResizableControlExtender ID="ResizableTextBoxExtender"
 runat="server" TargetControlID="PanelText"

    ResizableCssClass="resizingText" HandleCssClass="handleText OnClientResizing="OnClientResizeText" />

in to the user controller it might not be recognized after the page is rendered. 呈现给用户控制器后,页面呈现后可能无法识别。

try using Page.IsValid in your Submit button event. 尝试在“提交”按钮事件中使用Page.IsValid

if (!Page.IsValid) {
  return;
}

Sorry for all the trouble, 对不起,所有的烦恼,

There was one control on page which was hidden and required field validator for that control was not disabled. 页面上有一个隐藏的控件,并且未禁用该控件的必填字段验证器。 I disabled it using jQuery like 我使用jQuery禁用了它

$(document).ready(function () {
    if (!$("#<%=TextBoxResizable.ClientID %>").is(":visible")) {
        ValidatorEnable(<%=rfvTextBoxResizable.ClientID %>, false);
    }
})

Asteric is visible after placing required field validator outside Panel. 在面板上放置所需的字段验证器后,可以看到Asteric。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM