/// <summary> /// Writes the NameLine content to the specified HtmlTextWriter object, for display on the client. /// </summary> /// <param name="nameLine">The NameLine to Render</param> /// <param name="name">The name of the NameLine, e.g. Title or Postcode</param> /// <param name="cssClass">A CSS to attach to the name line's input element.</param> /// <param name="writer">An HtmlTextWriter that represents the output stream to render HTML content on the client.</param> private void RenderNameLine(NameLine nameLine, string name, string cssClass, HtmlTextWriter writer) { if (nameLine.Visible) { writer.RenderBeginTag("tr"); writer.WriteLine(); writer.Indent++; // Render the label cell writer.RenderBeginTag("td"); if (nameLine.ShowLabel == true) { // ShowLabel is true so render the label control into the label cell this.FindControl(string.Format(CultureInfo.InvariantCulture, "{0}_Label", name)).RenderControl(writer); } writer.RenderEndTag(); if (cssClass != null) { writer.AddAttribute(HtmlTextWriterAttribute.Class, cssClass); } writer.RenderBeginTag("td"); this.FindControl(string.Format(CultureInfo.InvariantCulture, "{0}_TextBox", name)).RenderControl(writer); writer.RenderEndTag(); // render the validation writer.AddAttribute(HtmlTextWriterAttribute.Class, "errorCell"); writer.RenderBeginTag("td"); if (nameLine.Mandatory == true) { // Input for this name line is mandatory so render out the RequiredFieldValidator this.FindControl(string.Format(CultureInfo.InvariantCulture, "{0}_RequiredFieldVal", name)).RenderControl(writer); } if (nameLine.ValidationExpression != null) { this.FindControl(string.Format(CultureInfo.InvariantCulture, "{0}_RegularExpressionVal", name)).RenderControl(writer); } writer.RenderEndTag(); writer.Indent--; writer.Indent--; writer.RenderEndTag(); } }
/// <summary> /// Called from CreateChildControls to create the necessary child controls for an NameLine /// </summary> /// <param name="nameLine">The NameLine to create the controls for</param> /// <param name="name">Name of the NameLine, e.g. title, givenName etc.</param> private void CreateNameLineChildControls(NameLine nameLine, string name) { if (nameLine.Visible == true) { if (nameLine.ShowLabel == true) { // A label is requested for this name line is mandatory so create a Label Label lbl = new Label(); lbl.ID = string.Format(CultureInfo.InvariantCulture, "{0}_Label", name); lbl.AssociatedControlID = string.Format(CultureInfo.InvariantCulture, "{0}_TextBox", name); lbl.Text = nameLine.LabelText; this.Controls.Add(lbl); } if (nameLine.Mandatory == true) { // Input for this name line is mandatory so create a RequiredFieldValidator RequiredFieldValidator rfv = new RequiredFieldValidator(); rfv.ID = string.Format(CultureInfo.InvariantCulture, "{0}_RequiredFieldVal", name); rfv.ControlToValidate = string.Format(CultureInfo.InvariantCulture, "{0}_TextBox", name); rfv.Display = ValidatorDisplay.Dynamic; rfv.ErrorMessage = "* required field"; this.Controls.Add(rfv); } if (nameLine.ValidationExpression != null) { // A validation expression has been specified for this NameLine so create a RegularExpressionValidator RegularExpressionValidator regfv = new RegularExpressionValidator(); regfv.ID = string.Format(CultureInfo.InvariantCulture, "{0}_RegularExpressionVal", name); regfv.ControlToValidate = string.Format(CultureInfo.InvariantCulture, "{0}_TextBox", name); regfv.Display = ValidatorDisplay.Dynamic; regfv.ValidationExpression = nameLine.ValidationExpression; regfv.ErrorMessage = "* invalid data"; this.Controls.Add(regfv); } TextBox tb = new TextBox(); tb.ID = string.Format(CultureInfo.InvariantCulture, "{0}_TextBox", name); this.Controls.Add(tb); // Pass the textbox down to the name line so it can refer to it internally nameLine.PassInputControl(tb); } }