Postback/Validation in a framework

G

Guest

Hi.
We have a framework that we work with for our project. So far we
have had very good success – basically the frame work wraps many day to day
tasks so that they are all included in the project. The framework is built on
a modified Page Controller pattern in which a aspx page controls the loading
of clients (user controls) into a placeholder (Sort of similar to .net 2.0
Master Pages except that the page loads the client not the client loads the
page) – and therefore it can provide many services to the client controls –
such as logging, Home page layout, Request parameter validation , session
introspection (for customer support) , ui messaging (i.e. Messageboxing) etc…



The problem we are having is with validation. Using the standard
asp.net server side validation the developer has to include an explicit
validation check in a posted back event i.e

If (Page.IsValid)
{
Do stuff
}

If page.isvalid is not checked then the code will run even if the values in
the controls are flat out wrong.

One of the aims of our framework is too automatically take care
of as many things as we can offload off the developer – this is something
that is probably ripe for inclusion – basically what I am looking for is a
way to interrupt the page load process so that we can stop postback events
from firing if the page is not valid.

I cannot find anyway of interrupting the validation process.
Ideally I want be able to stop the actual code written in the postback events
(such as onselection changed) from firing. The problem is that I do not see
anywhere that I can hook into this. I want to catch it after it has applied
the values to the controls and before it actually calls the postback events
however everything is marked as private.

I did think about actually unassigning the postback events in
onload (after validation) - however there are so many different types of
events I would have to look for - Including many controls that I do not
currentlly have (third Party). However ifI don't have a choice I might have
to resort to that.

Does any one have any ideas?
Thanks
 
J

John Saunders

AIM48 said:
Hi.
We have a framework that we work with for our project. So far
we
have had very good success - basically the frame work wraps many day to
day
tasks so that they are all included in the project. The framework is built
on
a modified Page Controller pattern in which a aspx page controls the
loading
of clients (user controls) into a placeholder (Sort of similar to .net 2.0
Master Pages except that the page loads the client not the client loads
the
page) - and therefore it can provide many services to the client
controls -
such as logging, Home page layout, Request parameter validation , session
introspection (for customer support) , ui messaging (i.e. Messageboxing)
etc.
....

One of the aims of our framework is too automatically take care
of as many things as we can offload off the developer - this is something
that is probably ripe for inclusion - basically what I am looking for is a
way to interrupt the page load process so that we can stop postback events
from firing if the page is not valid.

Do you currently stop processing your pages in Page_Load if Page.IsValid is
false? I've never written a page like that. I check IsValid when it's time
to maybe change data.

John Saunders
 
J

John Saunders

AIM48 said:
We have many things happening in the page load and I do not stop
processing
on the isvalid call. Rather I would like to automaticlly dissconnect the
postback events if !page.isvalid

What I'm getting at is that this seems unnatural to me. I can't say that
I've written many web applications where every postback event began with "if
not page.isValid return".

John Saunders
 
P

Peter Blum

ASP.NET is designed so that you check Page.IsValid in you post back event
method prior to saving when there are validators on the page. There are a
few cases:
* If CausesValidation=true, the button will fire Page.Validate() for you
just before calling your click event. It doesn't skip calling your click
event (which is what AIM48 wants). You have to test Page.IsValid
* If CausesValidation=false, then you are responsible for making validation
decisions by calling Page.Validate() or Validator.Validate() and testing the
associated IsValid property.
Its very common for users not to understand this and get into trouble with
it.

AIM48: I have a suggestion. Subclass System.Web.UI.WebControls.Button with
the following changes:
- Add a method that checks Page.IsValid and internally connect it to the
Click event.
- Add a new event to this class which is used as a replacement for Click.
For example: "RealClick".
- You Click event method will fire the RealClick events if Page.IsValid is
true.
- You teach your users to use your new class and assign the event RealClick
instead of Click.

IMO, its no easier than teaching them to use ASP.NET the standard way.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top