Stupid Validator Question

  • Thread starter Thread starter seanmayhew
  • Start date Start date
S

seanmayhew

I want the little "*" error message that displays next to a text box of
my validation to display when the page loads NOT on the button click so
that the user knows what fields are required BEFORE the try to save the
form.....Im sure this is obvious but I could not find the answer any
help greatly appreciated.
 
protected void Page_Load(object sender, EventArgs e)
{
Page.Validate();
}
 
Maarten said:
protected void Page_Load(object sender, EventArgs e)
{
Page.Validate();
}

This will work but has a drawback. If you use this, and also have a
ValidationSummary control on your page, the errors will be listed on the
first page load, instead of just postbacks. If you do have a
ValidationSummary control on the page, then what you can do is set the
Display property of the Validation control(s) you are using to "None".
Place a label (styled) next to the controls that you are validating with an
'*' char as the text. This way, the '*' are always visible (styled to Red
forecolor if you so desire) and the error messages are only displayed in the
ValidationSummary on a validation check. You would no longer need
Page.Validate() in your Page_Load event.

HTH,
Mythran
 
Perhaps do

if(!page.ispostback)
{
Page.Validate();
myvldsummary.visible = false;
}
 

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

Back
Top