nmduc073 posted on April 16, 2009 06:00

::589 view(s)
Hôm nay, định làm demo cái custom validator trên Dotnenuke. Search 1 hồi thì mình lại thấy cái custom validator control của .NET. Thực sự trước giờ chưa dùng nó bao giờ. Tệ thật.
Cái control này hỗ trợ cho cả validate trên server side và client side. Khá hay.
Mình có thử làm 1 cái test demo cho nó
<asp:TextBox runat="server" ID="tbox"></asp:TextBox>
<asp:LinkButton runat="server" ID="lbtn" Text="Click" onclick="lbtn_Click"></asp:LinkButton>
<asp:CustomValidator runat="server" ID="cVa" ClientValidationFunction="CheckForHardCodedValue" OnServerValidate="ValidateServerSide" ErrorMessage="**" ControlToValidate="tbox" Text="Custom cua ASP"></asp:CustomValidator>
<script language="javascript" type="text/javascript">
function CheckForHardCodedValue(source, arguments)
{
var tID = '<%= tbox.ClientID %>';
if (document.getElementById(tID).value == 'GOLD')
arguments.IsValid = true;
else
arguments.IsValid = false;
}
</script>
[Read the rest of this article...]