E
Elad Volpin
Can someone please explain this:
I created a new webform with a PlaceHolder and a Button.
My Page_Load contains the following code:
private void Page_Load(object sender, System.EventArgs e)
{
ListControl l = null;
ListItem item = new ListItem("a", "b");
item.Selected = true; // <--- causes exception
if ( !IsPostBack )
l = new RadioButtonList();
else
l = new CheckBoxList();
l.Items.Add(item);
this.PlaceHolder1.Controls.Add(l);
}
The RadioButtonList appears just fine at first. If I click on the
button, then instead of seeing a CheckBoxList, I get the following
exception:
'Length cannot be less than zero. Parameter name: length'.
If I comment out the 'item.Selected = true;' from the code, then the
behaviour is as follows:
1. If I don't select the radio button (i.e. submits a 'cleared'
button) and click the regular button, then I get to see the
CheckBoxList just fine.
2. If I do select the radio button, then I get the same exception
(just as if the 'item.Selected = true;' was not commented out).
I know I can workaround this problem - thats easy. But can someone
explain this behaviour?
Thanks,
Elad.
I created a new webform with a PlaceHolder and a Button.
My Page_Load contains the following code:
private void Page_Load(object sender, System.EventArgs e)
{
ListControl l = null;
ListItem item = new ListItem("a", "b");
item.Selected = true; // <--- causes exception
if ( !IsPostBack )
l = new RadioButtonList();
else
l = new CheckBoxList();
l.Items.Add(item);
this.PlaceHolder1.Controls.Add(l);
}
The RadioButtonList appears just fine at first. If I click on the
button, then instead of seeing a CheckBoxList, I get the following
exception:
'Length cannot be less than zero. Parameter name: length'.
If I comment out the 'item.Selected = true;' from the code, then the
behaviour is as follows:
1. If I don't select the radio button (i.e. submits a 'cleared'
button) and click the regular button, then I get to see the
CheckBoxList just fine.
2. If I do select the radio button, then I get the same exception
(just as if the 'item.Selected = true;' was not commented out).
I know I can workaround this problem - thats easy. But can someone
explain this behaviour?
Thanks,
Elad.