Setting ValidationGroup to RequiredFieldValidator from a property is not configured correctly

I am trying to set my required validatorsGroup fields dynamically from a property on my page, however they do not fire. If I set the line manually, it fires. My guess is that it did not pull the property properly in the ValidationGroup. Did I miss something?

<asp:RequiredFieldValidator runat="server" ID="rfvHouseName" ControlToValidate="txtHouseName" ErrorMessage="Please enter a house name/no." ForeColor="Red" ValidationGroup="<%#ValidationGroup%>"><i class="fa fa-star requiredFieldStar"></i></asp:RequiredFieldValidator>
<asp:TextBox ID="txtHouseName" runat="server" MaxLength="50" CssClass="form-control" />

private static string _validationGroup = "NewAddress";

public virtual string ValidationGroup
{
    get { return _validationGroup; }
    set { _validationGroup = value; }        
}
+4
source share
1 answer

You must install it in the code for

rfvHouseName.ValidationGroup = ValidationGroup;

Or, if you really want to use it in a string, you should use it like this:

<asp:RequiredFieldValidator ValidationGroup='<%# ValidationGroup %>'

However, for the second to work, you have to call DataBind()from code every time .

protected void Page_Load(object sender, EventArgs e)
{
    DataBind();
}
+2
source

Source: https://habr.com/ru/post/1687022/


All Articles