Validation - substitution of null with "0"

  • Thread starter Thread starter Pao
  • Start date Start date
P

Pao

I have to validate some textboxes.
The rule is that only numbers and null values are good.
But in case of null values, I have to substitute them with "0".

How can I do? thanks
 
...
But in case of null values, I have to substitute them with "0".
How can I do? thanks

Hey,

You didn't mention whether this was going to be client or server side, but
something along these lines...

If txtMyTextBox.Text = String.Empty Then

txtMyTextBox.Text = "0"

End If

You should be able to adapt this quite easily to iterate through the
textboxes on the page perhaps by iterating through the form and thus remove
the dependancy to know the name of each text box.

I don't tend to dabble client side, but I'm sure something similar would be
possible with javascript, and again, iterating through.

HTH

Regards

Rob
 
Rob Meade ha scritto:
...


Hey,

You didn't mention whether this was going to be client or server side, but
something along these lines...

If txtMyTextBox.Text = String.Empty Then

txtMyTextBox.Text = "0"

End If

Thank you Rob, I have to do that server side, but I can't do like your
example as I use a formview control bounded to an objectdatasource.
So when I have some textboxes with no values, and the property of my
object is Int, it generates an error.
I tried to intercept some event like OnInserting, but in the code I
can't reach the textboxes of the ItemTemplate.
For this reason I want prevent the problem by validating the textboxes,
but in case of null how can I put a "0" ? I read somewhere that regular
expressions can also substitute values but wasn't teached how...
 
Back
Top