开发者

Range Validator problem

I have a GridView with a textbox in one of its fields. I use a range validator to make sure the user enters only "x" character:

<asp:TextBox ID="txtMP3Master" runat="server" Text='<%# Eval("MP3Master") %>' BorderStyle="None" Width="80%" MaxLength="1" onchange="JSSaveNTSChanges(this);"></asp:TextBox>  
<asp:RangeValidator ID="MP3MasterRangeValidator" runat="server" ControlToValidate="txtMP3Master" Display="Dynamic" ErrorMessage="MP3 Master can be nothing but 'x'" Text="*" MinimumValue="x" MaximumValue="x" ValidationGroup="InsertUpdateNewTitlesStatusValidation">
</asp:RangeValidator>

The validator displays "*" on invalid input, but JSSaveNTSChanges() is still called. I want this function call blocked on invalid input. BTW, CompareValidator works correctly in other fields and blocks corresponding fun开发者_开发知识库ctions from being called. Is it possible to fix this problem? Thanks.


You should use CompareValidator instead of RangeValidator.

Here is what I have tested on my end. Just try it..

<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="CompareValidator"
        ValueToCompare="x"  ControlToValidate="txtMP3Master"></asp:CompareValidator>


I'm not sure if your function JSSaveNTSChanges will be called before or after the validator validation. But I recommend one of the 2 options below:

  1. Move the JSSaveNTSChanges in the submit button click.
  2. Call this function in a custom validator with EnableClientValidation = true
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜