How to Prevent PostBack Event Handler from Firing

Posted by user331744 on Stack Overflow See other posts from Stack Overflow or by user331744
Published on 2010-05-03T20:32:51Z Indexed on 2010/05/03 20:38 UTC
Read the original article Hit count: 215

Filed under:

I have a custom class (ServerSideValidator.vb) that validates user input on server side (it doesn't use any of the .NET built in validators, therefore Page.Validate() is not an option for me). I am calling the Validate() method on page.IsPostback event and the class performs without any problem

My issue is, when validation fails (returns false), I want to stop the postback event handler from firing, but load the page along with all the controls and user-input values in them. If I do, Response.End(), the page comes up blank. I can programmatically instruct the page to go to the previous page (original form before postback), but it loses all user-inputs.

I thought of creating a global boolean variable in the page code behind file and check the value before performing any postback method, but this approach takes away from my plan to provide all functionalities inside the class itself. The page object is being referenced to ServerSideValidator.

Seems like all the postback related properties/variables I come across inside Page class are 'Readonly' and I can't assign value(s) to control/prevent postback event from firing.

Any idiea on how I can accomplish this? Please let me know if you need further details

© Stack Overflow or respective owner

Related posts about ASP.NET