Dynamically generating control validators

Discussion in 'ASP .Net' started by -=Chris=-, Nov 9, 2003.

  1. -=Chris=-

    -=Chris=- Guest

    I'm developing a custom server control that will be rendering a form based
    on some input. I've tried creating custom validators in vb.net like so:

    Dim v1 as RequiredValidator = new RequiredValidator()
    Dim vs as ValidationSummary = new ValidationSummary()

    RequiredValidator.ControlToValidate = "id of form control here"
    RequiredValidator.Enabled = True
    RequiredValidator.EnableClientScript = True
    RequiredValidator.ErrorMessage = "Test message"

    ValidationSummary.ShowSummary = False
    ValidationSummary.ShowMessageBox = True
    ValidationSummary.EnableClientScript = True
    ValidationSummary.Enabled = True


    Now when I submit the form, I have a piece of code in the button's onclick
    event that does:

    Response.Write "Page Validity: " & Me.IsValid

    When the fields are not filled in properly, me.IsValid returns false as
    expected, but the ValidationSummary never displays the messagebox. It's
    almost like the validation controls have to be registered with the
    validation summary somehow, and that's not happening.

    Any ideas? What am I missing?


    Thanks in advance,
    Chris

    --
    Insert corny line here
    -=Chris=-, Nov 9, 2003
    #1
    1. Advertising

  2. -=Chris=-

    bill Guest

    How about
    Page.Controls.Add( vs );

    -=Chris=- wrote:

    > I'm developing a custom server control that will be rendering a form based
    > on some input. I've tried creating custom validators in vb.net like so:
    >
    > Dim v1 as RequiredValidator = new RequiredValidator()
    > Dim vs as ValidationSummary = new ValidationSummary()
    >
    > RequiredValidator.ControlToValidate = "id of form control here"
    > RequiredValidator.Enabled = True
    > RequiredValidator.EnableClientScript = True
    > RequiredValidator.ErrorMessage = "Test message"
    >
    > ValidationSummary.ShowSummary = False
    > ValidationSummary.ShowMessageBox = True
    > ValidationSummary.EnableClientScript = True
    > ValidationSummary.Enabled = True
    >
    >
    > Now when I submit the form, I have a piece of code in the button's onclick
    > event that does:
    >
    > Response.Write "Page Validity: " & Me.IsValid
    >
    > When the fields are not filled in properly, me.IsValid returns false as
    > expected, but the ValidationSummary never displays the messagebox. It's
    > almost like the validation controls have to be registered with the
    > validation summary somehow, and that's not happening.
    >
    > Any ideas? What am I missing?
    >
    >
    > Thanks in advance,
    > Chris
    >


    --
    bill
    e-mail:
    MSN Messenger:
    Web: http://www.minivoice.com
    bill, Nov 9, 2003
    #2
    1. Advertising

  3. -=Chris=-

    -=Chris=- Guest

    No dice. I even tried adding the summary control through the IDE using
    drag/drop to make sure it was registered. Still no message.

    I was minding my own business when bill blurted out:

    > How about
    > Page.Controls.Add( vs );
    >
    > -=Chris=- wrote:
    >
    >> I'm developing a custom server control that will be rendering a form

    based
    >> on some input. I've tried creating custom validators in vb.net like so:
    >>
    >> Dim v1 as RequiredValidator = new RequiredValidator()
    >> Dim vs as ValidationSummary = new ValidationSummary()
    >>
    >> RequiredValidator.ControlToValidate = "id of form control here"
    >> RequiredValidator.Enabled = True
    >> RequiredValidator.EnableClientScript = True
    >> RequiredValidator.ErrorMessage = "Test message"
    >>
    >> ValidationSummary.ShowSummary = False
    >> ValidationSummary.ShowMessageBox = True
    >> ValidationSummary.EnableClientScript = True
    >> ValidationSummary.Enabled = True
    >>
    >>
    >> Now when I submit the form, I have a piece of code in the button's

    onclick
    >> event that does:
    >>
    >> Response.Write "Page Validity: " & Me.IsValid
    >>
    >> When the fields are not filled in properly, me.IsValid returns false as
    >> expected, but the ValidationSummary never displays the messagebox. It's
    >> almost like the validation controls have to be registered with the
    >> validation summary somehow, and that's not happening.
    >>
    >> Any ideas? What am I missing?
    >>
    >>
    >> Thanks in advance,
    >> Chris


    --
    Insert corny line here
    -=Chris=-, Nov 9, 2003
    #3
    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. Christian H
    Replies:
    2
    Views:
    562
    Christian H
    Jul 23, 2003
  2. Tony
    Replies:
    1
    Views:
    858
  3. Ratman
    Replies:
    0
    Views:
    644
    Ratman
    Sep 14, 2004
  4. Jeffrey Todd
    Replies:
    1
    Views:
    4,090
    Peter Blum
    Jun 2, 2005
  5. krish
    Replies:
    0
    Views:
    289
    krish
    Mar 2, 2007
Loading...

Share This Page