6

I managed to have my dependent droplists (WFFM dependent drop lists) populated via a custom WFFM RuleAction by using a lot of JavaScript but now since I add dynamically the values in my second droplist when I submit the WFFM form I get the error:

Invalid postback or callback argument.

As I read on stack some questions and answers I came to the conclusion that I need to register all my dynamic values I add to this list by using ClientScript.RegisterForEventValidation(unique id, value) but it seems this has to be made in a Render() method of the control.

I searched a method to overwrite or to make a call to some method in my custom RuleAction but haven't found anything.

Does anyone knows how can I make the call to RegisterForEventValidation method in a RuleAction class or at least disable the droplist validation so I could press the submit button and don't get the validation error?

Edit:

I found a way I could get my values registered but I get an error:

Demo code:

public class ChangingDropListPopulatesDropList<T> : RuleAction<T> where T : ConditionalRuleContext
{
    public override void Apply([NotNull] T ruleContext)
    {
        Assert.ArgumentNotNull(ruleContext, nameof(ruleContext));

        if (((ruleContext.Control == null) || !ruleContext.Control.Visible) && (ruleContext.Model == null))
        {
            return;
        }

        if (ruleContext.Control != null)
        {
            ...
            ruleContext.Control.SetRenderMethodDelegate(this.RenderCustom);
        }
    }

    protected void RenderCustom(System.Web.UI.HtmlTextWriter writer, System.Web.UI.Control Container)
    {
    }
}

The error I get is:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

enter image description here

5

Not sure if it is possible to call RegisterForEventValidation from inside RuleAction.

You can try different approach. Instead of adding your values from javascript add all possible values into dropdown on WFFM form designer and then hide some of them with javascript. Thanks to this you will not have to register any values for valudation.

1
  • 1
    Tried different tricks but by far this is the best solution I found. Also by using this your droplist selection value will be submitted correctly if you want to send it over an email or save to db. Thanks @Bartłomiej Mucha. – Adrian C. Sep 21 '16 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.