Checkout control cannot find its checkout control
I have a repeater associated with a number of custom dataitems / types
in the itemdatabound event for the repeater, the code calls the renderedit function, which, depending on the custom data type, will render the custom control. it also (if the validation flag is set) renders the validation control for the corresponding render control
the edit control overrides the CreateChildControls () method for the custom control by adding multiple literalControls, thus
protected override void CreateChildControls()
{
//other bits removed - but it is this 'hidden' control i am trying to validate
this.Controls.Add(new LiteralControl(string.Format(
"<input type=\"text\" name=\"{0}\" id=\"{0}\" value=\"{1}\" style=\"display:none;\" \">"
, this.UniqueID
, this.MediaId.ToString())
));
//some other bits removed
}
the checkout control looks like this: where passed to editcontrol is the control instance, above which the above createchildcontrols is the method ..
public override Control RenderValidationControl(Control editControl)
{
Control ctrl = new PlaceHolder();
RequiredFieldValidator req = new RequiredFieldValidator();
req.ID = editControl.ClientID + "_validator";
req.ControlToValidate = editControl.UniqueID;
req.Display = ValidatorDisplay.Dynamic;
req.InitialValue = "0";
req.ErrorMessage = this.Caption + " cannot be blank";
ctrl.Controls.Add(req);
return ctrl;
}
the problem is that all the controls are validated. The ControlToValidate property is set by the unique editcontrol. when I click on the page I get the following error: Could not find the control id 'FieldRepeater $ ctl01 $ ctl00' referenced by the ControlToValidate property 'FieldRepeater_ctl01_ctl00_validator'.
I tried changing the literal in createchildcontrols to a new TextBox () and then setting the id, etc., but I get a similar problem.
Can anyone enlighten me? is it because of the order in which the controls are displayed? those. is the check control written before editing? or...
anyway any help appreciated
thanks
physical
a source to share