How to validate() User Control at Page submit?

Discussion in 'ASP .Net' started by owingruters, Jul 15, 2004.

  1. owingruters

    owingruters Guest

    Hi all,

    I've created an User control. It's an extension of a textbox wich has
    some extra properties so that validation becomes a lot faster.

    The control wordks great if autopostback is on. When there's a value
    in the textbox, the (overridden) textchanged event fires and
    validation is performed.

    Now I want to turn off autopostback. So I want my contol only validate
    if the submit button is pressed. I've tried Page.Validate(), but It
    seems only to trigger Validators. My control doesn't have to have
    validators, but just raises an error.

    So, I think the question is: how do I trigger the overridden
    textchanged event of my custom control, preferably without writing
    code in de click event of the submit-button?

    Greetz,
    Owin
    Amsterdam
     
    owingruters, Jul 15, 2004
    #1
    1. Advertising

  2. "owingruters" <-spam.invalid> wrote in message
    news:...
    > Hi all,
    >
    > I've created an User control. It's an extension of a textbox wich has
    > some extra properties so that validation becomes a lot faster.
    >
    > The control wordks great if autopostback is on. When there's a value
    > in the textbox, the (overridden) textchanged event fires and
    > validation is performed.
    >
    > Now I want to turn off autopostback. So I want my contol only validate
    > if the submit button is pressed. I've tried Page.Validate(), but It
    > seems only to trigger Validators. My control doesn't have to have
    > validators, but just raises an error.
    >
    > So, I think the question is: how do I trigger the overridden
    > textchanged event of my custom control, preferably without writing
    > code in de click event of the submit-button?



    Owin, perhaps you'd do better to use the validation framework. I hope the
    following will help:

    ASP.NET Validation in Depth
    (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/htm
    l/aspplusvalid.asp).
    --
    John Saunders
    johnwsaundersiii at hotmail
     
    John Saunders, Jul 15, 2004
    #2
    1. Advertising

  3. The text changed event should fire if the text in the box is different on
    post back whether that post back was triggered by an auto post back or by
    the submit button.

    To make certain the control is valid use: If Page.IsValid Then

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "owingruters" <-spam.invalid> wrote in message
    news:...
    > Hi all,
    >
    > I've created an User control. It's an extension of a textbox wich has
    > some extra properties so that validation becomes a lot faster.
    >
    > The control wordks great if autopostback is on. When there's a value
    > in the textbox, the (overridden) textchanged event fires and
    > validation is performed.
    >
    > Now I want to turn off autopostback. So I want my contol only validate
    > if the submit button is pressed. I've tried Page.Validate(), but It
    > seems only to trigger Validators. My control doesn't have to have
    > validators, but just raises an error.
    >
    > So, I think the question is: how do I trigger the overridden
    > textchanged event of my custom control, preferably without writing
    > code in de click event of the submit-button?
    >
    > Greetz,
    > Owin
    > Amsterdam
    >
     
    S. Justin Gengo, Jul 15, 2004
    #3
  4. owingruters

    owingruters Guest

    Thank you both.

    The article did not contain a solution, but it made some things clear
    about the sequence in which events are handled.

    And S. Justin...You were right. The event does fire. But there is one
    difference: When my usercontrols Non_Validating event fires and
    valdation failes, I turn the IsValid property of a CustomValidator to
    false, to prevent the page from Validating.

    With the autopostback property on, this is the only event that fires,
    so the cuctomvalidator and the page are invalid.
    When I turn the autopostback off and use a submit button to submit the
    page, the bottum_click event also fires and as I found out does a
    Page.Validate().
    If I turn the IsValid property to false in the Non_validating event,
    the Page.IsValid property also changes to falsen. Then the
    Page.Validate() method is executes, and the Page.IsValid property is
    set to true again.

    The only way I can solve this seemes to me to make a private variable
    to remember if the control valided or not and set the
    customvalidator.Isvald property again in the button_click event.

    This works, but I don't want the users of my custum control to have to
    know all these things.

    Have u got any ideas of how to solve this?
    My only idea left is to not make a custom textbox, but a custom
    customvalidator :) that performs the validation that I want.

    Thanx for any help,
    Owin
     
    owingruters, Jul 16, 2004
    #4
  5. Re: re:How to validate() User Control at Page submit?

    Owen,

    I think you've thought this out well. A "custom" custom validator is
    probably the best way to go.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "owingruters" <-spam.invalid> wrote in message
    news:...
    > Thank you both.
    >
    > The article did not contain a solution, but it made some things clear
    > about the sequence in which events are handled.
    >
    > And S. Justin...You were right. The event does fire. But there is one
    > difference: When my usercontrols Non_Validating event fires and
    > valdation failes, I turn the IsValid property of a CustomValidator to
    > false, to prevent the page from Validating.
    >
    > With the autopostback property on, this is the only event that fires,
    > so the cuctomvalidator and the page are invalid.
    > When I turn the autopostback off and use a submit button to submit the
    > page, the bottum_click event also fires and as I found out does a
    > Page.Validate().
    > If I turn the IsValid property to false in the Non_validating event,
    > the Page.IsValid property also changes to falsen. Then the
    > Page.Validate() method is executes, and the Page.IsValid property is
    > set to true again.
    >
    > The only way I can solve this seemes to me to make a private variable
    > to remember if the control valided or not and set the
    > customvalidator.Isvald property again in the button_click event.
    >
    > This works, but I don't want the users of my custum control to have to
    > know all these things.
    >
    > Have u got any ideas of how to solve this?
    > My only idea left is to not make a custom textbox, but a custom
    > customvalidator :) that performs the validation that I want.
    >
    > Thanx for any help,
    > Owin
    >
     
    S. Justin Gengo, Jul 16, 2004
    #5
    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?T3dpbg==?=
    Replies:
    2
    Views:
    1,250
    Mike Smith
    Jul 15, 2004
  2. Mad Scientist Jr
    Replies:
    0
    Views:
    639
    Mad Scientist Jr
    Mar 22, 2006
  3. Replies:
    2
    Views:
    474
  4. Paul Oakfleet
    Replies:
    1
    Views:
    855
    Chris Riesbeck
    Sep 10, 2003
  5. Replies:
    1
    Views:
    698
    Randell D.
    Mar 17, 2005
Loading...

Share This Page