1

I have a Repeater with a TextBox and a RegularExpressionValidator (REV) on every row. I bind the validationexpression for REVs in the aspx by doing,

<asp:RegularExpressionValidator ID="regexTeam" ErrorMessage="myerrormessage" 
       ValidationGroup="ValidationGroup1" Display="None" 
       ControlToValidate="txtTeam" runat="server" 
       ValidationExpression='<%# MyNamespace.Constants.RegularExpression.myvalidationexpressionconstant %>'>
</asp:RegularExpressionValidator>

This works fine.

Now I have another place(not within the Repeater) with the same kind of TextBox and an REV. I do the same:

<asp:RegularExpressionValidator ID="regexStatus" ErrorMessage="myerrormessage" 
        ValidationGroup="ValidationGroup2" Display="None" 
        ControlToValidate="txtStatus" runat="server" 
        ValidationExpression='<%# MyNamespace.Constants.RegularExpression.myvalidationexpressionconstant %>'>
</asp:RegularExpressionValidator>

The second one does not work. It does not accept any input. In the page source, there is no regexstatus.validationexpression. The regexteam.validationexpression exists as expected. Any ideas?

PS: The constants are defined in a separate project in a struct. I cannot make it a static class.

Kelsey
  • 46,456
  • 16
  • 122
  • 161

1 Answers1

0

In the one not in the Repeater, there is no 'bind' action happening so the <%# code is not firing.

You can call a bind at the page level to cause it to fire if you want but not sure what the side effects of that would be or you can use <%= instead that just executes regardless of binding.

Kelsey
  • 46,456
  • 16
  • 122
  • 161