How to validate() User Control at Page submit?

O

owingruters

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
 
J

John Saunders

owingruters said:
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).
 
S

S. Justin Gengo

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
 
O

owingruters

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

S. Justin Gengo

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top