RequiredFieldValidator in action immediately in fresh form

P

peshrad

Hi !

I'm using Visual Studio .NET to program a Web application coding in C#.

In my form I use an HtmlSelect control that calls a JavaScript function when
the selected item changes.
This JavaScript function calls the submit() method of the form.

For this HtmlSelect control I have also programmed the ServerChange event,
which is able to dynamically set up the form.

Depending on the item selected, this set-up adds an input field and an
associated RequiredFieldValidator.
I want the input field to be empty initially, but, unfortuantely,
the RequiredFieldValidator seems to act immediately when the fresh page
comes from the server.

I didn't have this problem as long as I was using a
System.Web.UI.WebControls.DropDownList instead of the HtmlSelect control,
but I would like to keep the Html control, in order to call my own
JavaScript when the selected item changes.

Is there a way to suppress the above mentioned initial validation when the
page is loaded afresh.

Your kind advice would be appreciated.

Peter
 
P

Peter Blum

When the page is set to IsPostBack=true, each validator shows its error
message when the IsValid property is false. Try this: after the page is
validated (you are probably calling Page.Validate()), set the
RequiredFieldValidator.IsValid property to true.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top