Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Dynamically created Validation controls

Dynamically created Validation controls

Scheduled Pinned Locked Moved C#
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nidhi s
    wrote on last edited by
    #1

    I have dynamically created the textboxes .Now I want to add a Requiredfield validator with a txtbox. I am trying like this: TextBox txtBoxReEnterPassword = new TextBox(); ---Some other Code---- RequiredFieldValidator rfldValidator = new RequiredFieldValidator(); rfldValidator.Text = "Enter same Password"; rfldValidator.ID = "compvaldtor"; rfldValidator.ErrorMessage = "Enter Password"; rfldValidator.ControlToValidate = "txtReEnterPassword"; txtBoxReEnterPassword.Controls.Add(rfldValidator); But it's not working.

    E N 2 Replies Last reply
    0
    • N Nidhi s

      I have dynamically created the textboxes .Now I want to add a Requiredfield validator with a txtbox. I am trying like this: TextBox txtBoxReEnterPassword = new TextBox(); ---Some other Code---- RequiredFieldValidator rfldValidator = new RequiredFieldValidator(); rfldValidator.Text = "Enter same Password"; rfldValidator.ID = "compvaldtor"; rfldValidator.ErrorMessage = "Enter Password"; rfldValidator.ControlToValidate = "txtReEnterPassword"; txtBoxReEnterPassword.Controls.Add(rfldValidator); But it's not working.

      E Offline
      E Offline
      Eduard Keilholz
      wrote on last edited by
      #2

      What is the error you receive??

      Nidhi.s wrote:

      txtBoxReEnterPassword.Controls.Add(rfldValidator);

      You're not supposed to add the validator as control of the textbox, you should add the control to, for example, your form... this.Controls.Add(); further, the use if strings is a but... erhm... fault sensitive.. use ControlInstance.Name in stead of "txtReEnterPassword";

      .: I love it when a plan comes together :. http://www.zonderpunt.nl

      1 Reply Last reply
      0
      • N Nidhi s

        I have dynamically created the textboxes .Now I want to add a Requiredfield validator with a txtbox. I am trying like this: TextBox txtBoxReEnterPassword = new TextBox(); ---Some other Code---- RequiredFieldValidator rfldValidator = new RequiredFieldValidator(); rfldValidator.Text = "Enter same Password"; rfldValidator.ID = "compvaldtor"; rfldValidator.ErrorMessage = "Enter Password"; rfldValidator.ControlToValidate = "txtReEnterPassword"; txtBoxReEnterPassword.Controls.Add(rfldValidator); But it's not working.

        N Offline
        N Offline
        netJP12L
        wrote on last edited by
        #3

        I think you need to tell the TextboxReEnterPasssword field to use requiredFieldValidator as a FieldValidationId. Try doign it first on Designview atleast you would know how it works and what are the parameters.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups