Adding validation controls programmatically

Discussion in 'ASP .Net Building Controls' started by D Sheldon, May 11, 2004.

  1. D Sheldon

    D Sheldon Guest

    I am creating a server control that adds web controls (i.e. textboxes, etc) to a form. I use HtmlTable to build the table and insert the controls. Now I want to add validators to the textbox. Here is the code that I am using:

    bool lastnamerequired=false;
    public bool LastNameRequired
    {
    get{return lastnamerequired;}
    set{lastnamerequired = value;}
    }

    if(lastnamerequired)
    {
    System.Web.UI.WebControls.RequiredFieldValidator rfv = new RequiredFieldValidator();
    rfv.ControlToValidate = "sFirstName";
    rfv.Display = ValidatorDisplay.Dynamic;
    rfv.Text = "";
    rfv.ErrorMessage = "Required";
    rfv.EnableClientScript = true;
    rfv.ID = "rfvFirstName";
    td.Controls.Add(rfv);
    }

    This code seems to only add the word "Required" to my form when rendered. It's not dynamic nor does it go away when the field is valid.

    Any ideas?
     
    D Sheldon, May 11, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RCBTaGVsZG9u?=

    Adding validation controls programmatically

    =?Utf-8?B?RCBTaGVsZG9u?=, May 11, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,856
    =?Utf-8?B?RCBTaGVsZG9u?=
    May 11, 2004
  2. Tim Marsden

    Adding controls programmatically.

    Tim Marsden, May 19, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    591
    Steven Cheng[MSFT]
    May 25, 2004
  3. Chakravarti Mukesh

    Adding Controls Programmatically

    Chakravarti Mukesh, Jan 10, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    4,007
    brijesh patel
    Feb 14, 2013
  4. Replies:
    0
    Views:
    498
  5. Jav

    Programmatically enabling Validation Controls

    Jav, Sep 2, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    419
Loading...

Share This Page