Refactor Code

  • Gravatar
    Validation Input for the UI

    by azamsharp on 5/5/2008 6:12:14 PM
  • How do you validate the controls on the page? Specially, when checking for required fields. Let's say you have 10 textboxes and they are all required would you use a requiredfieldvalidator control for each of the textboxes.
  • <asp:TextBox id="txtName" runat="server" />

    <asp:RequiredFieldValidator id="rfvName" runat="server" ControlToValidate="txtName" ErrorMessage = "!" />
  • Refactor it!
  • Gravatar
    I generally create a TextField control that contains: * Label * Textbox * Validator(s) and then just use properties to control how/if they are displayed. so in your case, you could have 10 TextField controls that look like this:
    by subdigital on 5/6/2008 8:27:41 AM
  • Gravatar
    (code didn't make it through)
    by subdigital on 5/6/2008 8:28:18 AM
  • <my:TextField id="txtName" runat="server" Label="Name" Required="true" />
    <my:TextField id="txtPhone" runat="server" Label="Phone #" Required="true" ValidateNumeric="true" />
  • Gravatar
    I also think that a multi required field validator control would be a good idea. Simply, insert the textbox id and the message to be displayed and the control will take care of the rest.
    by azamsharp on 5/6/2008 10:50:48 AM
  • Gravatar
    I would usually name my textboxes sequentially such as "txtRequired1, txtRequired2" then do a loop. This is when I use a custom validator. Just my 2 cents but it's good to know the other methods out there as far as validation.
    by the_menace on 9/22/2008 4:42:06 PM
Please log in to refactor the code! Login