By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,422 Members | 1,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,422 IT Pros & Developers. It's quick & easy.

Allowing blank values for validated textbox

P: n/a
Hello:

I'm using the validating event on a text boxes to test for valid
dates, doubles, etc. The problem is that if the field is not required
and a blank value is OK and the user deletes a previous non-blank
value, the validaing event keeps putting the non-blank value back in
the text box and doesn't allow the blank value. Is this unavoidable
in the built-in validating event and do I need just to write my own
validation event?

Thanks,

Ken
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Ken Loomis wrote:
Hello:

I'm using the validating event on a text boxes to test for valid
dates, doubles, etc. The problem is that if the field is not required
and a blank value is OK and the user deletes a previous non-blank
value, the validaing event keeps putting the non-blank value back in
the text box and doesn't allow the blank value. Is this unavoidable
in the built-in validating event and do I need just to write my own
validation event?

Thanks,

Ken


The validation should just verify the value, not write anything.
Are you sure you don't put it back yourself by accident?
Or that you skip blank field when you store the contents,
so the non-blank value will not be overwritten?

Do you have some code to show?

Hans Kesting
Nov 17 '05 #2

P: n/a
On Wed, 27 Jul 2005 10:17:16 +0200, "Hans Kesting"
<ne***********@spamgourmet.com> wrote:
Ken Loomis wrote:

I'm using the validating event on a text boxes to test for valid
dates, doubles, etc. The problem is that if the field is not required
and a blank value is OK and the user deletes a previous non-blank
value, the validaing event keeps putting the non-blank value back in
the text box and doesn't allow the blank value. Is this unavoidable
in the built-in validating event and do I need just to write my own
validation event?


The validation should just verify the value, not write anything.
Are you sure you don't put it back yourself by accident?
Or that you skip blank field when you store the contents,
so the non-blank value will not be overwritten?


Hans, thanks for your reply. If I comment out the validating event,
the blank value sticks. That's what made me think it was the
validation that was causing it.

This is what I have for validating:

private void txtHours_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
if (txtHours.Text.Length != 0 )
{
try
{
double hours = Convert.ToDouble(txtHours.Text);
}
catch
{
this.errorProvider1.SetError(txtHours,"Enter hours in 1.00
format");
e.Cancel = true;
}
}
}

And here's what I have for validated:

private void txtHours_Validated(object sender, System.EventArgs e)
{
this.errorProvider1.SetError(txtHours,"");
}

Ken
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.