I've created a custom server control in ASP.NET to render a standard checkbox and a hidden field like this:
public class CheckAllBox : WebControl
{
private string checkboxClientID;
protected override void OnInit(EventArgs e)
{
checkboxClientID = String.Format("{0}{1}chbCheckAll", base.ClientID, base.ClientIDSeparator);
base.OnInit(e);
}
protected override void Render(HtmlTextWriter writer)
{
//Render checkbox
writer.AddAttribute(HtmlTextWriterAttribute.Id, checkboxClientID);
writer.AddAttribute(HtmlTextWriterAttribute.Name, checkboxClientID);
writer.AddAttribute(HtmlTextWriterAttribute.Type, "checkbox");
writer.AddAttribute(HtmlTextWriterAttribute.Value, Values);
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();
//Render hidden field
writer.AddAttribute(HtmlTextWriterAttribute.Id, String.Format("{0}{1}hdnExcludeValues", base.ClientID, base.ClientIDSeparator));
writer.AddAttribute(HtmlTextWriterAttribute.Name, String.Format("{0}{1}hdnExcludeValues", base.ClientID, base.ClientIDSeparator));
writer.AddAttribute(HtmlTextWriterAttribute.Type, "hidden");
writer.AddAttribute(HtmlTextWriterAttribute.Value, ExcludeValues.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();
}
}
Now I want to retrieve the value of the hidden field and the checkbox when it is posted back - is it possible with the standard html I have rendered?
I've already written jQuery that works with this markup but it does require a standard html checkbox with a value - not the kind of checkbox rendered by ASP.NET.
If it is not possible to retrieve the value from standard html inputs, do I need to rewrite this as a composite control, or is there another trick?