I am using a user control (for phone number), and I have some validations inside it and this user-control is used at multiple places at the system, and I need to pass the ValidationGroup to it from the place where it is used, but this is NOT working (the validation not fired) and the user can submit the form without entering the phone number
Note: The submit button already has the same validation group
Here is the code of the user control
<div runat="server" ID="DivContainer" class="control-group">
<label class="control-label">Phone Number<span class="required">*</span></label>
<div class="row-fluid">
<div class="span6">
<asp:DropDownList runat="server" ID="DdlCountryPhoneCodes" CssClass="span12" />
</div>
<div class="span6">
<input type="text" maxlength="50" cssclass="span12" runat="server" id="TxtPhoneNumber" />
</div>
</div>
<div class="validation-message-wrapper">
<asp:RequiredFieldValidator runat="server" CssClass="validation-message" ErrorMessage="Enter your phone number." ValidationGroup="<%= ValidationGroup %>" Display="Dynamic" ControlToValidate="TxtPhoneNumber" />
<asp:CustomValidator runat="server" ID="CustomValidatorTxtPhoneNumber" ControlToValidate="TxtPhoneNumber" Display="Dynamic" CssClass="validation-message" ValidationGroup="<%= ValidationGroup %>" ClientValidationFunction="validatePhoneNumber" />
</div>
Here is an example of the usage of the user control
<uc1:RecoveryPhoneNumber runat="server" ID="ucRecoveryPhoneNumber" ValidationGroup="ManageAccountGroup" />
Q: How to make the validation work at any place the user-control used?
ValidationGroupwhich you set on the page where user control is placed. Inside the usercontrol you have validator controls e.g. RequiredField and CustomValidator. On user control Page_Load event you can set the ValidationGroup property of each validator control to the user control ValidationGroup property e.g.CustomValidatorTxtPhoneNumber.ValidationGroup = this.ValidationGroup