Blog Tools
Edit My Blog
RSS Feed RSS
About Me
Contact Me

< < May 2012 > >
S M T W T F S
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
You are not signed in.
Sign in

Entries By Topic
·All Topics RSS
·ASP.NET RSS
·ASP.NET Web Pages (Razor) RSS
·Classic ASP RSS
·Cool Websites RSS
·Databases RSS
·eBay/PayPal RSS
·General RSS
·Hardware RSS
·HTML/CSS RSS
·Jquery/Javascript RSS
·Media Center RSS
·Mobile Phones RSS
·Web Design RSS
·Web Security RSS
·Windows XP RSS

Search
 
Recent Entries
·RadioButton CheckedChanged event doesn't fire if default value is checked
·Login with Facebook in ASP.NET C# - Retrieve user details
·ASP.NET C# Error Notification and Flood Control
·jobs.nsw - web user interface design at its worst
·eBay Tip: How to find what best offers have been accepted
·eBay Changes Starting 22 September 2011
·You've heard of Shazam, but there are alternatives
·The Commodore 64 Lives On
·Jquery/Javascript plugin to truncate text to fit container height and width
·Multiple Projects in Visual Web Developer 2010 (VWD)

John's Technology Blog

RadioButton CheckedChanged event doesn't fire if default value is checked

Posted at: March 27, 2012
Related Topic(s): ASP.NET

Whether a bug or by design, if you have a radio button with autopostback set to true and you set the default value to true, the CheckedChanged event will not fire if the RadioButton is the trigger for an AJAX UpdatePanel but outside of the panel.

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)");

View Comments (0) | Add Comment | Permalink

Newer | Latest | Older

Car Workshop Manuals & Books, Auto, Truck, Motorcycle, Tractor, Outboard

Car Workshop Manuals & Books, Auto, Truck, Motorcycle, Tractor, Outboard

Steel Mesh Sheets & Fence Panels - Blacktown NSW

[Quicksales is an Australian auction website which offers no listing fees]

Web Design - Northern Beaches