Reputation: 3153
I got this error when I placed the unique id of the control in the source code. Below is the source code.
<ucPopupMember:PopupMember ID="PopupMember_MemberID"
runat="server"
TextBoxMaxLength="12"
ValidationGroup="SpkrSetupGroup"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator_MemberID"
runat="server"
ErrorMessage="Member ID is required"
Text="*"
CssClass="errorlabel"
ValidationGroup="SpkrSetupGroup"
Display="Dynamic"
ControlToValidate="ctl00$ContentPlaceHolder_MainContent$TabContainer1$TabPanel_Entry$PopupMember_MemberID$TextBox_MemberCode"/>
How to I change this or fix this? I'm having problems because of the "$" sign.
[UPDATE] The control to validate (textbox) is inside the user control.
Upvotes: 0
Views: 1457
Reputation: 15663
You need to specify the "server" ID of the control for the ControlToValidate property. Both controls need to exist in the same container.
In the PopupMember control add the validator there:
<asp:RequiredFieldValidator ID="RequiredFieldValidator_MemberID"
runat="server"
ErrorMessage="Member ID is required"
Text="*"
CssClass="errorlabel"
ValidationGroup="SpkrSetupGroup"
Display="Dynamic"
ControlToValidate="MemberCode"/>
I suppose the member code is always required so you don't have to anything more.
But if the MemberCode sometimes is not required, add a property in the code behind of the PopupMember control.
public bool MemberRequired
{
set {RequiredFieldValidator_MemberID.Visible = value;}
}
By default is required. If you don't need it required by default use in markup Visible="false"
Upvotes: 1
Reputation: 429
Apart from what @Adrian suggested, I think the Beginning and Ending should look like this:
<asp:RequiredFieldValidator>
</asp:RequiredFieldValidator>
Upvotes: 0