Hi,
You can use this for both purpose by adding property.
user control
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="uctextBox.ascx.cs" Inherits="UserControlRegulerExpressionValidator.uctextBox" %>
<table><tr><td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1"
runat="server" ErrorMessage="RequiredFieldValidator" ValidationGroup="ucval" Enabled="false" ></asp:RequiredFieldValidator></td><td><asp:Button ID="Button1"
runat="server" Text="Button" ValidationGroup="ucval" /></td></tr></table>
code behind of the user control
protected void Page_Load(object sender, EventArgs e)
{
if (MyProperty)
RequiredFieldValidator1.Enabled = MyProperty;
}
public bool MyProperty { get; set; }
Your page code behind
protected void Page_Load(object sender, EventArgs e)
{
uctextBox1.MyProperty = true;
}
simply enable and disable user control reqiured field validator using the property.
If you need more clarifications please ask and improve this code according to your requirement and don not forget to mark as answer if this helps to you.