This project is read-only.

Association: SaveData Question

Aug 7, 2008 at 1:45 PM

Hi,

I have a scenario where I do some validation on the data entered in the Association control.  I need to prevent the user from saving if certain controls are not populated or have invalid selections.  I know i can throw an exception and the return page will handle it for me.  I need a more elegant solution where the user stays on the page and does not get routed to the exception page.  What are my options?

Regards
Jaco

Aug 7, 2008 at 3:57 PM
Really depends on if you are using their forms to host your control. I'm assuming you are, since that's what the demo suggests. In that case, you'll notice, for instance, in AssociationFormHost, that the event handler for the button clicks will not call CommitAssociation() if the page is not valid. So, just add a validator to the page and it'll fire automatically with the client side script.

Now, if you need to call Page.Validate() or do any other custom validation that isn't fired automatically by a postback, it's too late inside your control which derives from ConfigurationControl. In that case, since AssociationFormHost hasn't done it, you can probably just derive from the form host and override OnBubbleEvent() to do whatever you need. I haven't had to do this yet, but that seems like it should work from a brief inspection of the code.

If that doesn't work let me know and I'll spend more time playing with it.

Mike.
Aug 7, 2008 at 6:02 PM

I'm curious to see how this issue unfolds.  Our intention when writing the framework was to use the validators exactly as Mike suggested.  In the past in ASP.NET I've run into cases where this wasn't quite enough so we're open to updating the framework as needed.

If you'd let us know what works for you or post a little more information, we'll take a look at it.

Chris

Aug 8, 2008 at 7:52 AM

Hi Gents,

Thank you for the quick response.  I have used some validators and it seems Ok.  To give you some background;  I am writing a solution where ASPX screens / controls are generated using Xslt.  This provides us the flexibility to take the solution to any customer and no code changes are required, only Xslt changes.  The Xslt add some custom attributes to the ASPX controls that get interpreted by a server side interpreter and then spawns workflow instances on the data changes.  All of this will run in WSS / MOSS and this is where your framework comes into play.

I will have more detail in the next week or so and keep you updated on requests as well as where the frameworks works perfectly.

Regards

Jaco

 

Jan 6, 2009 at 7:04 PM
Edited Jan 6, 2009 at 7:05 PM
Here is what we did on the Instantiation form:

1. Add a custom validator
    <asp:CustomValidator runat="server" id="cvApprovers"
        ControlToValidate="rblDepartments"
        OnServerValidate="ValidateApprovers"
        ErrorMessage="The workflow can not be started as the selected department site does not have any assigned approvers. " />

2. In the custom validator code, set IsValid to false, depending on the condition. 

    public void ValidateApprovers(object sender, ServerValidateEventArgs args)
    {
        string selectedDepartmentUrl = rblDepartments.SelectedValue;

        // get approvers

        // fail validation if no approvers are found 
        if (approvers.Count == 0)
            args.IsValid = false;
    }

The OnBubbleEvent method on the host page will commit (call SaveData) only if validation passes. 

Hope this helps.