This can be reproduced using the following sample code:
Markup:
<asp:ScriptManager ID="ScriptManager" runat="server"></asp:ScriptManager>
<p><asp:RadioButton ID="rdoOne" runat="server" AutoPostBack="true" Checked="true" GroupName="Radios" OnCheckedChanged="rdoOne_CheckedChanged" Text="One" /></p>
<p><asp:RadioButton ID="rdoTwo" runat="server" AutoPostBack="true" GroupName="Radios" OnCheckedChanged="rdoTwo_CheckedChanged" Text="Two" /></p>
<asp:UpdatePanel ID="panResult" runat="server">
<ContentTemplate>
<p><asp:Literal ID="litResult" runat="server"></asp:Literal></p>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rdoOne" EventName="CheckedChanged" />
<asp:AsyncPostBackTrigger ControlID="rdoTwo" EventName="CheckedChanged" />
</Triggers>
</asp:UpdatePanel>
Code behind:
protected void rdoOne_CheckedChanged(object sender, EventArgs e)
{
litResult.Text = "One " + DateTime.Now;
}
protected void rdoTwo_CheckedChanged(object sender, EventArgs e)
{
litResult.Text = "Two " + DateTime.Now;
}
Notice that checking rdoOne has no result.
There are a couple of simple solutions to this problem.
1. Do not set checked="true" in the markup, instead do it in the code behind like this:
rdoOne.InputAttributes["checked"] = "true"
2. Add your own onclick event to rdoOne, like this:
rdoOne.Attributes.Add("onclick", "javascript:setTimeout('__doPostBack(\'" + rdoOne.ClientID.Replace("_", "$") + "\',\'\')', 0)");
Update: The real cure for this is to update the UpdatePanel containing the RadioButton, RadioButtonList, CheckBox or CheckBoxList (and add an UpdatePanel if you don't already have one) as ASP.NET is perfectly capable of sorting this out on its own if used as intended. I don't believe it's a bug, just the fact that sometimes ASP.NET controls need to be updated when certain things change.
Update: The real cure for this is to update the UpdatePanel containing the RadioButton, RadioButtonList, CheckBox or CheckBoxList (and add an UpdatePanel if you don't already have one) as ASP.NET is perfectly capable of sorting this out on its own if used as intended. I don't believe it's a bug, just the fact that sometimes ASP.NET controls need to be updated when certain things change.
Rate this post:
Comments
by CoOl | July 3, 2013
Great Help!!! Thanks.
Reply