Validation - substitution of null with "0"

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
 
R

Rob Meade

...
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
 
P

Pao

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...
 

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
474,433
Messages
2,571,683
Members
48,796
Latest member
Greg L.

Latest Threads

Top