Maybe this is also a bug in RadioButtonList
I'm using Visual Studio 2005, Ajax (UpdatePanel), a RadioButtonList which updates a DropDownList items.
Html code:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:RadioButtonList ID="rblType" runat="server" AutoPostBack="True" OnSelectedIndexChanged="rblType_SelectedIndexChanged" OnPreRender="rblType_PreRender" RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem Value="1" Selected="True">National</asp:ListItem>
<asp:ListItem Value="2">International</asp:ListItem>
</asp:RadioButtonList>
<asp:UpdatePanel ID="udpChannel" runat="server" ChildrenAsTriggers="False" RenderMode="Inline" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlChannel" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlChannel_SelectedIndexChanged"></asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rblType" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</form>
the RadioButtonList is rendered as:
<span id="rblType">
<input id="rblType_0" type="radio" name="rblType" value="1" checked="checked" />
<label for="rblType_0">National</label>
<input id="rblType_1" type="radio" name="rblType" value="2" onclick="javascript:setTimeout('__doPostBack(\'rblType$1\',\'\')', 0)" />
<label for="rblType_1">International</label>
</span>
You all can notice that the first radiobutton item has no onclick event. So, you're not able to verify if the first radio button item was clicked.
The only way to have a onclick event in the RadioButtonList first item was creating a workaround in behind code:
protected void rblType_PreRender(object sender, EventArgs e)
{
rblType.Items[0].Attributes.Add("onclick", "setTimeout('__doPostBack(\\'rblType$0\\',\\'\\')', 0)");
}
I don't know if my approach is correct. Did anyone have the same problem?