RequiredFieldValidator problem
Jeg har en UserControl, der arver fra RadioButtonList. Da der skal indsættes noget speciel formatering, overrider jeg Render() metoden. Jeg har en RequiredFieldValidator, der skal validere objektet, og i OnInit sætter jeg:requiredValidator.ControlToValidate = this.ID;
Min Render() metode ser således ud:
/// <summary>
/// This overrides the base class Render method to add some formatting
/// </summary>
/// <param name="htw"></param>
protected override void Render(HtmlTextWriter htw)
{
MyContext.Current.Trace.Write("Render","begin");
if ( myAttributes.requiredField)
{
htw.Write("<table><tr><td>");
MyContext.Current.Trace.Write("ValRadioButtonList ID",this.ID);
switch ( myAttributes.displayType )
{
case ValidationDisplayType.AboveInputBox:
requiredValidator.RenderControl(htw);
htw.Write("</td></tr><tr><td>");
base.Render(htw);
break;
case ValidationDisplayType.BelowInputBox:
base.Render(htw);
htw.Write("</td></tr><tr><td>");
requiredValidator.RenderControl(htw);
break;
case ValidationDisplayType.InSummary:
base.Render(htw);
htw.Write("</td><td align=right width=\"100%\">");
requiredValidator.RenderControl(htw);
break;
}
htw.Write("</td></tr></table>");
}
else
{
base.Render(htw);
}
MyContext.Current.Trace.Write("Render","end");
}
Problemet opstår, når requiredValidator.RenderControl() bliver kaldt. Jeg får følgende Exception:
Unable to find control id 'NameInputField' referenced by the 'ControlToValidate' property of 'RadioButtonsValidator'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Unable to find control id 'NameInputField' referenced by the 'ControlToValidate' property of 'RadioButtonsValidator'
Ved hjælp af Trace kan jeg se at this.ID ikke ændrer sig.
Hvad gør jeg galt ?