Web Control - Convert Input Value From String To Decimal [VB.Net]

M

Mythran

My WebControl inherits from WebControl and implements IPostBackDataHandler
and IValidator.

The WebControl has quite a few properties associated with it. The primary,
default property is "Value" of type Decimal.

In the implemented LoadPostData method for the IPostBackDataHandler
interface, I store the String value that was submitted by the postback.
This value is stored in a private member variable. I can't directly assign
the String value to the Value property because the String value may not be
valid, this is why I store it in a member variable. When Validate() is
called (for the IValidator implementation), I then validate the stored
String value and set IsValid to True or False based on whether the string
value is valid. If it is valid, I also update the Value property of the
WebControl to the proper value. I also have an AutoPostBack Boolean propery
on this control. When True, the client will automatically post back to the
server when the value is changed.

So, my problem:

I place my WebControl onto a form, place a button on the form with
CausesValidation set to True. When I click on the button, the validation
occurs correctly and my validation is performed and the Value is updated to
the correct value (if valid). When I set AutoPostBack to True on my
WebControl, the WebControl posts back to the server correctly, but
Validation does NOT fire. How can I force validation to fire so the Value
property will be updated?

I only want validation to occur if Page.Validate() or
MyWebControl.Validate() has been called, or if the user entered a new value
and AutoPostBack is set to True. I do not, for example, wnat the validation
to occur if the value is changed from the server (via code-behind).

Anyone have a clue what I just asked and have a suggestion?

Thanks,
Mythran
 

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

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top