textbox - asp.net "compare validator" validation -
i trying validate fromdate
& todate
textboxes in asp.net using compare validator script is:
<table><tr><td> <asp:scriptmanager id="scriptmanager1" runat="server"> </asp:scriptmanager> <asp:label id="label1" runat="server" text="fromdate:"> </asp:label> <asp:textbox id="fromdatetxt" runat="server" height="21px" width="103px" ></asp:textbox> <ajaxtoolkit:calendarextender id="fromdatetxt_calendarextender" runat="server" enabled="true" targetcontrolid="fromdatetxt"> </ajaxtoolkit:calendarextender> </td> <td> <asp:label id="label2" runat="server" text="todate:"></asp:label> <asp:textbox id="todatetxt" runat="server" height="21px" width="105px" ></asp:textbox> <ajaxtoolkit:calendarextender id="todatetxt_calendarextender" runat="server" enabled="true" targetcontrolid="todatetxt"> </ajaxtoolkit:calendarextender> </td> <asp:comparevalidator id="comparevalidatordate" runat="server" controltocompare="todatetxt" controltovalidate="fromdatetxt" display="none" errormessage="from date cannot greaterthan date" operator = "lessthanequal" type="date" validationgroup="datevalidation"></asp:comparevalidator> <td> <asp:button id="button1" runat="server" text="submit" onclick="button1_click" validationgroup="datevalidation" /> <asp:validationsummary id="validationsummarydate" showmessagebox="true" showsummary="false" validationgroup="datevalidation" runat="server" /></td></tr></table> </asp:panel>
this working fine! i'm getting message box when click button. want message box moment clicked date in todate
in calendar control, , textboxes must clear. please me out .
you can solve problem using "page_clientvalidate" function of javascript , "onclientdateselectionchanged" event of calendarextender.
you not need change comparevalidator i.e.
<asp:comparevalidator id="comparevalidatordate" runat="server" controltocompare="todatetxt" controltovalidate="fromdatetxt" display="none" errormessage="from date cannot greater date" operator="lessthanequal" type="date" validationgroup="datevalidation"></asp:comparevalidator>
you need add onclientdateselectionchanged event calendarextender
<ajaxtoolkit:calendarextender id="todatetxt_calendarextender" runat="server" enabled="true" targetcontrolid="todatetxt" onclientdateselectionchanged="validate" >
"validate" here javascript function. in function need use "page_clientvalidate" method of javascript as
var validate = function () { var isvalid = page_clientvalidate("datevalidation"); //parameter validation group if (!isvalid) { $("#<%= todatetxt.clientid %>").val(''); //jquery clear textbox } }
you can modify "validate" function per convenience.
i hope helped.
regards,
samar
Comments
Post a Comment