strange AJAX behavior

kcwallace

Centurion
Joined
May 27, 2004
Messages
175
Location
Austin, TX
I am using the following HTML code to manage my page. The problem is that the radio button "rbShowWearersAll" will not fire its event. Am I doing something wrong? the other four work perfectly

Code:
<asp:RadioButton ID="rbShowWearersAll" runat="server" GroupName="showWearers" 
    oncheckedchanged="rbShowWearers_CheckedChanged" Text="All" 
    AutoPostBack="True" />
 <asp:RadioButton ID="rbShowWearersActive" runat="server" 
     oncheckedchanged="rbShowWearers_CheckedChanged" GroupName="showWearers" 
    Text="Active" AutoPostBack="True" />
<asp:RadioButton ID="rbShowWearersInactive" runat="server" 
     oncheckedchanged="rbShowWearers_CheckedChanged" GroupName="showWearers" 
    Text="Inactive" AutoPostBack="True" />
<asp:UpdatePanel ID="UpdatePanel8" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:GridView 
            ID="gvWearers" runat="server" SkinID="gridviewSkin" 
            AutoGenerateSelectButton="True" 
            OnSelectedIndexChanging="gvWearers_SelectedIndexChanging" 
            OnPageIndexChanging="gvWearers_PageIndexChanging"                        
            AllowPaging="True" 
            PageSize="20" ></asp:GridView>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="rbShowWearersAll" EventName="CheckedChanged" />
        <asp:AsyncPostBackTrigger ControlID="rbShowWearersActive" EventName="CheckedChanged" />
        <asp:AsyncPostBackTrigger ControlID="rbShowWearersInactive" EventName="CheckedChanged" />
        <asp:AsyncPostBackTrigger ControlID="ImageButton1" EventName="Click" />
        <asp:AsyncPostBackTrigger ControlID="ImageButton2" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
 
It is a subset. It is inside of an AJAX Tab Control.

THere is nothing special about any of the radio buttons. I lterally just dragged them onto the page, and made the very basic changes that you can see above.

The code behind is very simple. It just changes the data source for the data grid, and refreshes it.

The problem is that the OnCheckedChanged event never get called.

I did get it to work if I changed the form so none of them are checked at page load, but this is undesireable.
 
Interesting issue indeed. This is what I get if I look at the page source:
Code:
[B]<input id="rbShowWearersAll" type="radio" name="showWearers" value="rbShowWearersAll" checked="checked" />[/B]
<label for="rbShowWearersAll">All</label>
<input id="rbShowWearersActive" type="radio" name="showWearers" value="rbShowWearersActive" 
onclick="javascript:setTimeout('__doPostBack(\'rbShowWearersActive\',\'\')', 0)" />
<label for="rbShowWearersActive">Active</label>
<input id="rbShowWearersInactive" type="radio" name="showWearers" value="rbShowWearersInactive" 
onclick="javascript:setTimeout('__doPostBack(\'rbShowWearersInactive\',\'\')', 0)" />
<label for="rbShowWearersInactive">Inactive</label>
If I set this radiobutton to checked="true" or even do it on Page_Load it doesn't set his onclick properties. And if I change my selection to any other radiobuttons the property "checked" remains unchanged.

Don't know what the issue is right now, but below is a solution that works:

Code:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True">
<asp:ListItem Selected="True">all</asp:ListItem>
<asp:ListItem>act</asp:ListItem>
<asp:ListItem>inact</asp:ListItem>
</asp:RadioButtonList>

And in codebehind:
Code:
Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) 
Handles RadioButtonList1.SelectedIndexChanged
        If Me.RadioButtonList1.Items(0).Selected = True Then
            'process
        ElseIf Me.RadioButtonList1.Items(1).Selected = True Then
            'process
        ElseIf Me.RadioButtonList1.Items(2).Selected = True Then
            'process
        End If
End Sub

The example was tested, but I didn't put a Tab control on it, also I didn't set any Triggers. Should work just fine, if not try with some triggers.

A simillar issue with Panel control, which enabled/disabled doesn't update it's child controls to a new state in this blog
 
If I set this radiobutton to checked="true" or even do it on Page_Load it doesn't set his onclick properties. And if I change my selection to any other radiobuttons the property "checked" remains unchanged.

Don't know what the issue is right now, but below is a solution that works:

Interesting problem you found. :)
It doesn't set the onclick event to the checked radio button like you say. This makes sense as clicking on the selected radiobutton isn't a change event so shouldn't cause a postback.

However, as you are using the update panel you prevent a full postback and only the content inside the update panel is updated. This means your radio buttons will not be rerendered and remain in the initial state which is now wrong.

Obviously you have a solution that works but you could also move the radiobuttons inside the update panel to fix it.

Anyway thanks for finding this.
 
I don't think that solves the problem. Indeed, I had OP's radiobuttons outside of UpdatePanel, but I recoded my test page to this:

Code:
<asp:UpdatePanel ID="UpdatePanel88" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:RadioButton ID="rbShowWearersAll" runat="server" GroupName="showWearers" 
oncheckedchanged="rbShowWearers_CheckedChanged" Text="All"  
AutoPostBack="True" />
<asp:RadioButton ID="rbShowWearersActive" runat="server" 
oncheckedchanged="rbShowWearers_CheckedChanged" GroupName="showWearers" 
Text="Active" AutoPostBack="True" />
<asp:RadioButton ID="rbShowWearersInactive" runat="server" 
oncheckedchanged="rbShowWearers_CheckedChanged" GroupName="showWearers" 
Text="Inactive" AutoPostBack="True" />
</ContentTemplate>
</asp:UpdatePanel>

It still works as described in my post above. There is no onclick and it remains as "checked" all the time (in Page Source). This behaviour occurs only when Checked="True" is set in properties or in Page_Load.

But, it does change a postback for the first RadioButton.
So, if they are inside an UpdatePanel all three postback, but the first one retains it's values - no onclick.
 
I don't think that solves the problem. Indeed, I had OP's radiobuttons outside of UpdatePanel, but I recoded my test page to this:

It still works as described in my post above. There is no onclick and it remains as "checked" all the time (in Page Source). This behaviour occurs only when Checked="True" is set in properties or in Page_Load.

But, it does change a postback for the first RadioButton.
So, if they are inside an UpdatePanel all three postback, but the first one retains it's values - no onclick.

What have you done in page load?

Does it similar to this:

Code:
if(!IsPostback)
{
rbShowWearersAll.Checked = true;
}
 
What have you done in page load?

Does it similar to this:

C#:
if(!IsPostback)
{
rbShowWearersAll.Checked = true;
}

the radiobutton is set at page load in the manner you wrote in the code for the original post. I cannot speak for the other poster's attempts at solving the problem
 
I tried both ways
- set Checked=true in properties of control at design-time
- and in Page_Load as you said: rbShowWearersAll.Checked = true;

Reading my previous post again, I discovered I didn't make it clear:
The solution JohnsHandle suggested (UpdatePanel) works!

It does solve OP's problem, but I'm interested in that "no onclick event" behavior of this RadioButton. Will check it when I get some time.
 
Back
Top