This message was discovered on microsoft.public.dotnet.framework.aspnet.webcontrols.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| Jonathan Levine |
Hello... excuse the dumb question, but I would like to validate the text in a textbox by comparing it to the text in a hidden input control. (I set the value of the hidden input control via JScript).
I have tried this:
<asp:TextBox id="CompareTextbox" runat="server" Width="122px" TextMode="Password"></asp:TextBox> <input id="CheckHidden" runat="server" Type="Hidden"/> <asp:CompareValidator id="CompareValidator" runat="server" ControlToValidate="CompareTextbox" Display="Dynamic" ControlToCompare="CheckHidden">No Match</asp:CompareValidator>
But I get a Server Error: Control 'CheckHidden' referenced by the ControlToCompare property of 'CompareValidator' cannot be validated
What am I missing?
|
|
|
| |
|
| |
| |
| Steven Cheng[MSFT] (VIP) |
Hi,
From your description, you're using compare validation control to validate a certain asp.net TExtBox control's value and he set the ControlToCompare property to a HtmlHiddenField control and get error at runtime,yes?
I think this is a normal behavior since the HtmlInputHIdden field is not the acceptable control to for being used by the CompareValidator. The "ControlToValidate" is generally set to the Id of another asp.net textbox control or HtmlInputText Control but not HtmlInputHidden control. In fact, we can verify this by pull the dropdownlist of the ControlToValidate property in VS.NET IDE's property window. it'll list out all the available controls to be set.
In addition, as for your situation, I think we can use CustomValidator control or manually use javascript function to compare the values in the two controls. How do you think of this? If you have any other ideas, please also feel free to post here. Thanks.
Regards,
Steven Cheng Microsoft Online Support
Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.)
Get Preview at ASP.NET whidbey http://msdn.microsoft.com/asp.net/whidbey/default.aspx
|
|
|
| |
|
|
| |
| |
| Jonathan Levine |
Hi Steven,
"Steven Cheng[MSFT]" wrote: [Original message clipped]
That's right.
[Original message clipped]
That's too bad. I think it would be a useful enhancement.
[Original message clipped]
Actually, I took an idea from KB article 310082 and subclassed the HtmlInputHidden control. All I needed to do was add the ValidationProperty and everything works fine, e.g.:
using System; using System.Web.UI; using System.Web.UI.HtmlControls; using System.ComponentModel;
namespace ClientSideControls { /// <summary> /// Summary description for HiddenInput. /// </summary> [DefaultProperty("Value"), ValidationProperty("Value"), ToolboxData("<{0}:HiddenInput runat=server></{0}:HiddenInput>")] public class HiddenInput : HtmlInputHidden { } }
Regards,
Jonathan
|
|
|
| |
|
|
| |
| |
| Steven Cheng[MSFT] (VIP) |
Hi Jonathan,
Thanks very much for the response. And your solution that use the "ValidationProperty" according to the Kb article is so cool. I must say that is the best solution for this issue:). Also, thanks again for sharing your code sample with us. Have a good day!
Regards,
Steven Cheng Microsoft Online Support
Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.)
Get Preview at ASP.NET whidbey http://msdn.microsoft.com/asp.net/whidbey/default.aspx
|
|
|
| |
|
|
| |
|
|
|
|
|
|
|