protected void valCustQuantity_ServerValidate(object source, ServerValidateEventArgs args) { CustomValidator valCustQuantity = (CustomValidator)source; int quantity; if (StoreSettings.InventoryManagement && StoreSettings.AvoidNegativeStock && int.TryParse(args.Value, out quantity)) { string itemID = valCustQuantity.Attributes["ItemID"]; ItemInfo itemInfo = CurrentCart.GetItem(int.Parse(itemID)); ProductController controler = new ProductController(); ProductInfo currentProduct = controler.GetProduct(PortalId, itemInfo.ProductID); if (currentProduct.StockQuantity < quantity) { if (quantity > 1) { valCustQuantity.ErrorMessage = string.Format(Localization.GetString("ErrorQuantityPlural", LocalResourceFile), currentProduct.StockQuantity, currentProduct.ProductTitle); } else if (quantity == 1) { valCustQuantity.ErrorMessage = string.Format(Localization.GetString("ErrorQuantitySingular", LocalResourceFile), currentProduct.ProductTitle); } else { valCustQuantity.ErrorMessage = string.Format(Localization.GetString("ErrorQuantityNegative", LocalResourceFile), currentProduct.ProductTitle); } args.IsValid = false; } } }