This is how I create my checkbox:
HtmlInputCheckBox checkbox = new HtmlInputCheckBox();
checkbox.ID = _Data.ControlID;
checkbox.Attributes.Add("class", "checkbox");
checkbox.Attributes.Add("autocomplete", "off");
sReplacementString = element.RenderToString();
RenderToString is an extension that does this:
public static string RenderToString(this Control control)
{
StringBuilder sb = new StringBuilder();
using (StringWriter writer = new StringWriter(sb))
{
using (HtmlTextWriter htmlWriter = new HtmlTextWriter(writer))
{
control.RenderControl(htmlWriter);
}
}
return sb.ToString();
}
This creates a line with a closing tag in the input, I see this when debugging.
<input name="ttWBF_1" type="checkbox" id="ttWBF_1" autocomplete="off" class="checkbox" />
It is then added to HTML using the Agility Pack:
HtmlNode temp = doc.CreateElement("temp");
temp.InnerHtml = sReplacementString;
HtmlNode current = inputNode;
foreach (HtmlNode child in temp.ChildNodes)
{
inputNode.ParentNode.InsertAfter(child, current);
current = child;
}
inputNode.ParentNode.RemoveChild(inputNode);
However, in the HTML input tag for the flag, its self-closing slash is missing and, therefore, WC3 validation is not performed.
<input name="ttWBF_1" type="checkbox" id="ttWBF_1" autocomplete="off" class="checkbox">
This happens with my text fields that are generated in the same way. they seem to get lost when adding HTML to the page using the agility package.
How to prevent this?
source
share