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. <% ... %>).