Hello I have a custom CheckBoxList control so I can add attributes to listitems....
All works fine and I have a RadioButtonList that does the same, but for this when postingback multiple times and then changing the selected option I get the error
Length cannot be less than zero. Parameter name: length
further down in the trace output:
aspx.page Begin ProcessPostData 0.006315 0.000024
Unhandled Execution Error
Length cannot be less than zero.
Parameter name: length
at System.String.Substring(Int32 startIndex, Int32 length)
at System.String.Substring(Int32 startIndex)
at System.Web.UI.WebControls.CheckBoxList.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection)
at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad)
at System.Web.UI.Page.ProcessRequestMain()
here's the control, any ideas thanks!
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace myUI
{
/// <summary>
/// Summary description for AttributesCheckBoxList.
/// </summary>
public class AttributesCheckBoxList : System.Web.UI.WebControls.CheckBoxList
{
protected override void Render(HtmlTextWriter writer)
{
if (HasControls())
{
int i = 0;
foreach (ListItem listItem in Items)
{
writer.WriteBeginTag("input");
writer.WriteAttribute("ID",this.UniqueID+"_"+i );
writer.WriteAttribute("type", "checkbox");
writer.WriteAttribute("name", this.UniqueID);
writer.WriteAttribute("value", listItem.Value, true);
if (listItem.Selected)
writer.WriteAttribute("checked","true");
listItem.Attributes.Render(writer);
writer.Write('>');
writer.WriteEndTag("input");
writer.WriteBeginTag("label");
writer.WriteAttribute("for",this.UniqueID+"_"+i );
listItem.Attributes.Render(writer);
writer.Write('>');
HttpUtility.HtmlEncode(listItem.Text, writer);
writer.WriteEndTag("label");
if (i < Items.Count-1)
writer.RenderBeginTag(HtmlTextWriterTag.Br);
writer.WriteLine();
i++;
}
}
}
}
}