Results 1 to 11 of 11

Thread: requirefieldvalidate control for all text boxes

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    requirefieldvalidate control for all text boxes

    Hi, I have about 20 text boxes on my form, and I want to validate each field using the requiredFieldvalidate control; however, I don't want to add that control to each text box.. it's tiring Is there a way to do that?

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: requirefieldvalidate control for all text boxes

    No.

    You could make a user control called RequiredTextBox (or something) that contains a textbox and a requiredfieldvalidator.

  3. #3
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: requirefieldvalidate control for all text boxes

    In fact here's one I made quite sometime ago. It's pretty basic but did what I needed at the time and should give you an idea.

    RequiredTextBox.ascx
    Code:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="RequiredTextBox.ascx.cs" Inherits="Controls_RequiredTextBox" %>
    <asp:TextBox ID="requiredTextBox1" runat="server" /><asp:RequiredFieldValidator ID="rfv1" runat="server" Text="*" ControlToValidate="requiredTextBox1" Display="Dynamic" />
    RequiredTextBox.ascx.cs
    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class Controls_RequiredTextBox : System.Web.UI.UserControl
    {
        public bool Password
        {
            set { this.requiredTextBox1.TextMode = TextBoxMode.Password; }
        }
    
        public string ErrorText
        {
            set { this.rfv1.Text = value; }
        }
    
        public string ErrorMessage
        {
            set { this.rfv1.ErrorMessage = value; }
        }
    
        public string Text
        {
            get {return this.requiredTextBox1.Text; }
            set { this.requiredTextBox1.Text = value; }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
    Usage:
    Code:
    <%@ Register TagPrefix="fishcake" TagName="RequiredTextBox" Src="~/Controls/RequiredTextBox.ascx" %>
    ....
    <fishcake:RequiredTextBox ID="txtCompanyName" runat="server" />
    Last edited by Fishcake; Dec 5th, 2008 at 09:28 AM.

  4. #4
    Hyperactive Member koolprasad2003's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    443

    Arrow Re: requirefieldvalidate control for all text boxes

    Install Ajax control toolkit, it will more help ful for u
    MCP, MCTS, Microsoft MVP [Asp.Net/IIS]

    For more .NET development tips visit .NET Tips

    If the post is useful then please Rate it

  5. #5
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: requirefieldvalidate control for all text boxes

    Quote Originally Posted by koolprasad2003
    Install Ajax control toolkit, it will more help ful for u
    Which part of the Ajax toolkit and how would vbbit use it to solve his problem?

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: requirefieldvalidate control for all text boxes

    I don't recommend installing an entire set of class libraries or a framework for the sole purpose of using one tiny feature. It's overkill. I'd go with fishguy's solution or simply have twenty requiredfieldvalidators or do it all the codebehind in one go and present the user with the result of that validation.

  7. #7
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: requirefieldvalidate control for all text boxes

    Excuse me!!! I'm Fishcake, Fishguy is that other fish related user.

  8. #8
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: requirefieldvalidate control for all text boxes

    Quote Originally Posted by mendhak
    I don't recommend installing an entire set of class libraries or a framework for the sole purpose of using one tiny feature.
    Just curious, why? AjaxControlToolkit.dll is a single library that is to be deployed with your web solution. You use only the feature that you want.

  9. #9
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: requirefieldvalidate control for all text boxes

    Quote Originally Posted by rjv_rnjn
    Just curious, why? AjaxControlToolkit.dll is a single library that is to be deployed with your web solution. You use only the feature that you want.
    Well, that's the point. You are deploying an entire set of features in form of a single DLL file and using just a small feature which can be easily replicated using simple JS trick which is easier to create, use, implement and thus in turn, hassle-free.

    Not all controls in the kit use AJAX technique. There are some which use pure JS code. It's MS, who has clubbed everything in a single file and named it AJAX-something-something.dll!!!
    Show Appreciation. Rate Posts.

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: requirefieldvalidate control for all text boxes

    Quote Originally Posted by rjv_rnjn
    Just curious, why? AjaxControlToolkit.dll is a single library that is to be deployed with your web solution. You use only the feature that you want.
    If you had to perform one single stored procedure call in your website project, would you write the code yourself or add a reference to the DAAB and use SqlHelper just to avoid writing 3 lines of code?

    Both will work, one is overkill.

  11. #11
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: requirefieldvalidate control for all text boxes

    Ok..ok.. I get it! Don't beat me to death over it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width