DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Fri, 10 Aug 2007 14:52:50 -0400,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Mufasa
          2    Milosz Skalecki [MCAD]
                 3    Mufasa
          4    Braulio Diez


Is there any way to use a field validator to check if one value is less than another?   
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.
Date:Fri, 10 Aug 2007 14:52:50 -0400   Author:  

RE: Is there any way to use a field validator to check if one value is   
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.
> 
> 
> 
Date:Fri, 10 Aug 2007 12:46:05 -0700   Author:  

RE: Is there any way to use a field validator to check if one value is   
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.
> 
> 
> 
Date:Sat, 11 Aug 2007 10:34:01 -0700   Author:  

Re: Is there any way to use a field validator to check if one value is   
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.
>>
>>
>> 
Date:Mon, 13 Aug 2007 08:25:04 -0400   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us