ASP:TextBox or ASP:CheckBoxList, throwing Javascript errors when Requiredfield validator is there
I have created a User Control for my SharePoint, which has a simple TextBox
and a CheckBoxList
. For both of these controls, I have ASP:RequiredFieldValidator
and ASP:RegularExpressionValidator
.
When I select some item in the CheckBoxList
or type some input in the TextBox
, I am getting a javascript error in some unknown location. (This is not accepted by my customer.)
Now, when I debug this using FireBug, in the console I see validators[i]
is null. It is actually failing in the JS code generated by these validators.
Can some one help me?
Edited:
<asp:TextBox ID="txtNumbers" runat="server" CssClass="Label4" ></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidatorGPC" runat="server"
ControlToValidate="txtNumbers" ErrorMessage="Only Numbers Accepted "
ValidationExpression="^\d+$"
SetFocusOnError="true"></asp:RegularExpressionValidator>
<asp开发者_运维知识库:RequiredFieldValidator ID="RequiredNUMValue" runat="server" ControlToValidate="txtNumbers"
SetFocusOnError="true" ErrorMessage="Please enter a valid number"></asp:RequiredFieldValidator>
Also,
I added required field validators for RadioButtonList
(not CheckBoxList
).
<asp:RadioButtonList ID="rbtOptions" runat="server" CssClass="Label3">
<asp:ListItem Text="Option 1" />
<asp:ListItem Text="Option 2" />
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="rbtOptions"
SetFocusOnError="true" ErrorMessage="Please Select a Valid Option"></asp:RequiredFieldValidator>
When I either input any text in the TextBox
or select any option, there is a JavaScript error.
There is something else on your page that is conflicting with this. Taking what you posted and trying a simple page it works as it should, so I'm assuming that there's other elements / scripts that are causing this.
<div>
<asp:TextBox ID="txtNumbers" runat="server" CssClass="Label4"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidatorGPC" runat="server" ControlToValidate="txtNumbers" ErrorMessage="Only Numbers Accepted " ValidationExpression="^\d+$" SetFocusOnError="true"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="RequiredNUMValue" runat="server" ControlToValidate="txtNumbers" SetFocusOnError="true" ErrorMessage="Please enter a valid number"></asp:RequiredFieldValidator>
<asp:RadioButtonList ID="rbtOptions" runat="server" CssClass="Label3">
<asp:ListItem Text="Option 1" />
<asp:ListItem Text="Option 2" />
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="rbtOptions" SetFocusOnError="true" ErrorMessage="Please Select a Valid Option"></asp:RequiredFieldValidator>
<asp:Button ID="btnSubmit" runat="server" Text="submit" />
</div>
Do you have any script tags, or other elements in your markup that could be interfering with this?
Self closed tags can cause issues like this ( is a no no)
精彩评论