.netajaxcustomvalidatormultiviewexpando

Issue with multiview control and expando attributes


I have a multiview control which I effectively use the same as a wizard stepping through 4 panels to complete a form.

Each view has a number of input controls/validator controls. For reuse, these are bundled together as a user control. For instance my email user control contains a panel, with a label, textbox, required validator and regular expression validator.

I know that with the multiview everything is loaded, then controls outside the current view are hidden, however this is causing me a small issue and I'm looking for best suggestions as how to work around it.

Here's the scenario.

Panel 3 contains a user control called 'Number'. It has a panel, containing a label, textbox and a custom validator.

The control has properties that can be set (I usually set them in the containing aspx page), and the control is populated on page load.

Aspx page:

<uc4:Number ID="UC_Number" runat="server"
    Label="Monthly Take Home Pay" 
    MinValue="1"
    MaxValue="9999" />

Page_Load of number:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        SetValidation();
    }
}

The problem I have is in the SetValidation method.

    void SetValidation()
    {
        CusVal_ValueLimits.ErrorMessage = GetErrorMessage();

        if (MinValue > 0)
        {
            ScriptManager.RegisterExpandoAttribute(
                this,
                CusVal_ValueLimits.ClientID,
                "MinValue",
                MinValue.ToString(),
                false);
        }

        if (MaxValue > 0)
        {
            ScriptManager.RegisterExpandoAttribute(
                this,
                CusVal_ValueLimits.ClientID,
                "MaxValue",
                MaxValue.ToString(),
                false);
        }
    }

In order to allow custom validation on the client I add 2 new expando attributes. This causes an issue because the attributes are created but the user control is then hidden by the multiview.

This is not handled well by .net ajax code, and results in a javascript error because the user control referenced is not available, which in turn causes the rest of the javascript on the page to fall on its ar*e.

What I need to know is either, how do I load these user controls safely I.e. when the view is visible, or alter my expando related code to cope with this.

All ideas appreciated.


Solution

  • I resolved this by checking if the usercontrol was visible during pre-render if(this.Visible) and if so calling the expando stuff.