Figured out how to do it within a GridView (still no idea how it might work outside the GridView). Basically it comes down to adding in a data binding section where the max value would be entered (similar to binding a value to the TextBox itself):
<asp:RangeValidator ID="ShareTextBoxRangeValidator" runat="server"
ErrorMessage="!" ControlToValidate="ShareTextBox"
MaximumValue='<%# Eval("Cost") %>' MinimumValue="0"
Display="Dynamic" ClientIDMode="Predictable" Type="Double"/>
I found that Bind
and Eval
work equally well, but left it at Eval
since it won't be updating the data.
A further note about Validators and GridViews: If you have set your page's ClientIDMode
to Static, you must explicitly set it back to Predictable (or AutoID) on both the Validator and the control to be validated. Otherwise you will get key violation errors.