kamagra how much to take

Developing A Form WebPart – Part 4 – Setup the Validation Controls

The data that is being submitted with the Forms WebPart requires validation before it is committed to the database in order to maintain integrity of the information being stored. Doing validation with WebParts typically occurs in two main ways. One can choose to script a separate method in order to validate the entry by using an option like ServerValidateEventArgs.IsValid against the argument, or the inherent validation controls that ASP.NET 2.0 provides can be called in order to validate the information. Considering software architecture concerns and code bloat as a factor, it is typically preferable to use the inherent ASP.NET 2.0 validation options, which will also allow the extension of the validation being used to be assimilated by sister validation controls such as ValidationSummary.

Be aware that when using the inherent validation controls your WebPart will become subject to using client side script as the validation will depend on it. When leveraging the RequiredValidation controls in a WebPart, it will append some JavaScript to the form page on which it is added by calling ValidatorOnWSubmit(). There are known issues when trying to use multiple Form WebParts that use the inherent validation controls. SharePoint will always call the first validation control even when validating a secondary control on the page.

Here, you’re validating a numeric entry manually with a custom method.

  1.             public void ValidateNumeric(object source, ServerValidateEventArgs args)
  2.             {
  3.                 try
  4.                 {
  5.                     Decimal temp = Decimal.Parse(args.Value);
  6.                     args.IsValid = true;
  7.                 }
  8.                 catch
  9.                 {
  10.                     args.IsValid = false;
  11.                 }
  12.             }

And now, validate input using the native validation controls.

  1.             protected override void CreateChildControls()
  2.             {
  3.                 base.CreateChildControls();
  4.                 textTextBox = new TextBox();
  5.                 textTextBox.ID = "textTextBox";
  6.                 Controls.Add(textTextBox);
  7.                 rfvFieldValidator = new rfvFieldValidator();
  8.                 rfvFieldValidator.ControlToValidate = "textTextBox";
  9.                 Controls.Add(rfvFieldValidator);
  10.             }
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>