Friday, May 8, 2015

RadioButtonList SelectedIndexChanged Only Fires Once !!!

I ran into an interesting issue today.  The SelectedIndexChanged event was raised only once after page load.    The problem was solved by adding ClientIdMode="Static"   

<asp:RadioButtonList ID="rblTimeStamp" runat="server"
RepeatDirection="Horizontal" 
ClientIdMode="Static" AutoPostBack="True" OnSelectedIndexChanged="OnTimeStampTypeChanged" >
    <asp:ListItem Value="CurrentTime" Text="Current  "></asp:ListItem>
    <asp:ListItem Value="CustomTime"  Text="Custom" ></asp:ListItem>
</asp:RadioButtonList>

Don't use a RadAjaxManager if you set the ClientIdMode to Static.  See blog post titled "RadAjaxManager and ClientIdMode="Static".

Another Approach Using RadAjaxManager

Don't set any ClientIdMode values to Static.

Set AutoPostBack to true for radiobuttonlist.
Set the radiobuttonlist as the initiator and updated control in the RadAjaxManager.
Reset the selected radiobutton in the event handler. 


<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"    DefaultLoadingPanelID="loadingPanelDlgInjections">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="rblInjectionListChoice">
           <UpdatedControls>  
                <telerik:AjaxUpdatedControl ControlID="rblInjectionListChoice"/>
                <telerik:AjaxUpdatedControl ControlID="radCmbInjectionSites" />
           </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="loadingPanelDlgInjections" runat="server" Skin="Default"></telerik:RadAjaxLoadingPanel>


<asp:RadioButtonList ID="rblInjectionListChoice" runat="server" RepeatDirection="Horizontal" AutoPostBack="True" 
     OnSelectedIndexChanged="rblInjectionListChoice_SelectedIndexChanged">
    <asp:ListItem value="shortList" Text="Short List&nbsp;&nbsp;" Selected="True"></asp:ListItem>
    <asp:ListItem value="longList" Text="Long List&nbsp;&nbsp;"></asp:ListItem>
</asp:RadioButtonList></div>

<telerik:RadComboBox ID="radCmbInjectionSites" runat="server" Width="100%"
          AutoPostBack="True"   RenderMode="Lightweight"
          Filter="StartsWith" EmptyMessage="Select Injection Site">
</telerik:RadComboBox>



Event Handler

//Iterate through the radio button list and reset the selected item
protected void rblInjectionListChoice_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem item in rblInjectionListChoice.Items)
{
if (item.Selected)
{
item.Selected = true;
}
}

//Add your code here.
}


Visit www.BlueCanyonSoftware.com if you  need custom software for your business.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.