user2393874
user2393874

Reputation: 70

RadioButtonList won't change after doPostBack - ASP.NET JS C#

I have a radioButtonList inside a Panel. The panel uses UpdatePanel to update its panel.

<asp:UpdatePanel ID="upnlTeacherDismissal" runat="server" UpdateMode="Conditional" OnLoad="tmrRefreshTeacher_OnTick">
  <asp:Panel ID="pnlDismissalTeacher" runat="server"; color:White; width:100%;">
    <asp:RadioButtonList ID="rbtnStatusDismissal" AutoPostBack="true"
                                runat="server" RepeatDirection="Horizontal" OnSelectedIndexChanged="rbtnStatusDismissal_OnSelectedIndexChanged" >
      <asp:ListItem ID="id1" Text="In Class" Value="1" />
      <asp:ListItem ID="id2" Text="Dismiss" Value="4" />
      <asp:ListItem ID="id3" Text="Field Trip" Value="5" />
    </asp:RadioButtonList>

The updatepanel refreshes every 5 seconds which is trigerred by Javascript function (I know there's timer from System.Class.UI but for some reason I have to use JS function). Here is the refresh function:

function refresh() {  
     //update teacher panel
     __doPostBack('<%=upnlTeacherDismissal.UniqueID%>', '');
}

setInterval(refresh, 5000);

When doPostBack, on behind code, I want to set the radio button value to the updated value from database but there's no any change from the UI (radiobutton value is still 1). The program will execute this function every 5 seconds (not from rbtnStatusDismissal_OnSelectedIndexChanged).

protected void tmrRefreshTeacher_OnTick(object sender, EventArgs e)
        {
    //... few lines to check the database if table changes 
    rbtnStatusDismissal.SelectedValue = (int)data.statusID; 
    //let's say (int)data.statusID equals 5
    upnlTeacherDismissal.Update();
}

I've tried to debug and see that .SelectedValue has been set to the value of the data.statusID (let's say 5). But the radio button's value in UI still equals 1 (instead of 5). What's wrong and what should I do?

Upvotes: 1

Views: 664

Answers (1)

Sumit Pathak
Sumit Pathak

Reputation: 661

its work perfectly for me you are missing something i edited and replace that

<asp:UpdatePanel ID="upnlTeacherDismissal" runat="server" UpdateMode="Conditional" >
  <ContentTemplate>
    <asp:Panel ID="pnlDismissalTeacher" runat="server" style="color:White; width:100%;">
      <asp:RadioButtonList ID="rbtnStatusDismissal" AutoPostBack="true" runat="server" RepeatDirection="Horizontal" OnSelectedIndexChanged="rbtnStatusDismissal_OnSelectedIndexChanged">
        <asp:ListItem ID="id1" Text="In Class" Value="1" />
        <asp:ListItem ID="id2" Text="Dismiss" Value="4" />
        <asp:ListItem ID="id3" Text="Field Trip" Value="5" />
      </asp:RadioButtonList>
    </asp:Panel>
  </ContentTemplate>
</asp:UpdatePanel>

on server side

protected void rbtnStatusDismissal_OnSelectedIndexChanged(object sender, EventArgs e)
{
    rbtnStatusDismissal.SelectedValue = "5";
    upnlTeacherDismissal.Update();            
}

and this js function

<script type="text/javascript">
    function refresh() {  
           //update teacher panel
           __doPostBack('<%=upnlTeacherDismissal.UniqueID%>', '');
        }

    setInterval(refresh, 5000);
</script>

if you have any question and will not get answer then ask in comments.

Upvotes: 1

Related Questions