I have two fields on a web page. The user enters the quantity they want. Then there's another field that allows them to laminate the items (these are posters). I want to make sure that the laminated count is less than or equal to the quantity ordered. Is there a way to do that without doing an autopost of the page? I'd like to use a validator that happens at the client end. TIA - Jeff.
Jeff, Please find an example below. Please also note it's easy to prepare a page that skips your client validation therefore server validation should be always present regardless of the client scripts: <div> <asp:TextBox runat="server" ID="quantityOrdered" Text="0" /> <asp:RequiredFieldValidator runat="server" ID="rfv1" ErrorMessage="Please enter order quantity" ControlToValidate="quantityOrdered" Display="Dynamic" /> <asp:RangeValidator runat="server" ID="rv1" ErrorMessage="A valid number 0 ... 2000000" ControlToValidate="quantityOrdered" Display="Dynamic" MinimumValue="0" MaximumValue="2000000" Type="Integer" /> </div> <div> <asp:TextBox runat="server" ID="laminatedCount" Text="0" /> <asp:RequiredFieldValidator runat="server" ID="rfv2" ErrorMessage="Please enter number of items for lamination" ControlToValidate="quantityOrdered" Display="Dynamic" /> <asp:RangeValidator runat="server" ID="rv2" ErrorMessage="A valid number 0 ... 2000000" ControlToValidate="laminatedCount" Display="Dynamic" MinimumValue="0" MaximumValue="2000000" Type="Integer" /> </div> <div> <asp:CustomValidator runat="server" ID="cv" ControlToValidate="laminatedCount" Display="Dynamic" ClientValidationFunction="ValidateQuantity" OnServerValidate="cv_ServerValidate" ErrorMessage="Number of laminated items must be less or equal items ordered" /> </div> <script type="text/javascript"> function ValidateQuantity(sender, e) { // ensure all the validators tested until now are valid if (Page_IsValid) { var ordered = parseInt(document.getElementById('<%=quantityOrdered.ClientID %>').value); var laminated = parseInt(document.getElementById('<%=laminatedCount.ClientID %>').value); e.IsValid = laminated <= ordered; } } </script> <asp:Button runat="server" ID="submit" Text="Submit" /> HTH -- Milosz "Mufasa" wrote: > I have two fields on a web page. The user enters the quantity they want. > Then there's another field that allows them to laminate the items (these are > posters). I want to make sure that the laminated count is less than or equal > to the quantity ordered. Is there a way to do that without doing an autopost > of the page? I'd like to use a validator that happens at the client end. > > TIA - Jeff. > > >
You can create as well a javascript function to perform the check and associate it to a customValidator, more info about custom validator (client side and server side): http://aspnet.4guysfromrolla.com/articles/073102-1.aspx HTH Braulio /// ------------------------------ /// Braulio Diez /// /// http://www.tipsdotnet.com /// ------------------------------ "Mufasa" wrote: > I have two fields on a web page. The user enters the quantity they want. > Then there's another field that allows them to laminate the items (these are > posters). I want to make sure that the laminated count is less than or equal > to the quantity ordered. Is there a way to do that without doing an autopost > of the page? I'd like to use a validator that happens at the client end. > > TIA - Jeff. > > >
Actually there's an even easier way - asp:CompareValidator Works great and is all client side. I'll still check on the server side though. Thanks for the help. J. "Milosz Skalecki [MCAD]" wrote in message news:953FF159-E39A-41C8-8CCD-5F9392B606D8@microsoft.com... > Jeff, > > Please find an example below. Please also note it's easy to prepare a page > that skips your client validation therefore server validation should be > always present regardless of the client scripts: > > <div> > <asp:TextBox runat="server" ID="quantityOrdered" Text="0" /> > <asp:RequiredFieldValidator runat="server" ID="rfv1" > ErrorMessage="Please enter order quantity" > ControlToValidate="quantityOrdered" Display="Dynamic" /> > <asp:RangeValidator runat="server" ID="rv1" > ErrorMessage="A valid number 0 ... 2000000" > ControlToValidate="quantityOrdered" Display="Dynamic" > MinimumValue="0" MaximumValue="2000000" > Type="Integer" /> > </div> > <div> > <asp:TextBox runat="server" ID="laminatedCount" Text="0" /> > <asp:RequiredFieldValidator runat="server" ID="rfv2" > ErrorMessage="Please enter number of items for lamination" > ControlToValidate="quantityOrdered" Display="Dynamic" /> > <asp:RangeValidator runat="server" ID="rv2" > ErrorMessage="A valid number 0 ... 2000000" > ControlToValidate="laminatedCount" Display="Dynamic" > MinimumValue="0" MaximumValue="2000000" > Type="Integer" /> > </div> > <div> > <asp:CustomValidator runat="server" ID="cv" > ControlToValidate="laminatedCount" Display="Dynamic" > ClientValidationFunction="ValidateQuantity" > OnServerValidate="cv_ServerValidate" > ErrorMessage="Number of laminated items must be less or equal items > ordered" /> > </div> > > <script type="text/javascript"> > function ValidateQuantity(sender, e) > { > // ensure all the validators tested until now are valid > if (Page_IsValid) > { > var ordered = > parseInt(document.getElementById('<%=quantityOrdered.ClientID %>').value); > var laminated = > parseInt(document.getElementById('<%=laminatedCount.ClientID %>').value); > > e.IsValid = laminated <= ordered; > } > } > </script> > > <asp:Button runat="server" ID="submit" Text="Submit" /> > > > HTH > -- > Milosz > > > "Mufasa" wrote: > >> I have two fields on a web page. The user enters the quantity they want. >> Then there's another field that allows them to laminate the items (these >> are >> posters). I want to make sure that the laminated count is less than or >> equal >> to the quantity ordered. Is there a way to do that without doing an >> autopost >> of the page? I'd like to use a validator that happens at the client end. >> >> TIA - Jeff. >> >> >>