简体   繁体   English

在doPostBack之后,RadioButtonList将不会更改-ASP.NET JS C#

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

I have a radioButtonList inside a Panel . 我在Panel内有一个radioButtonList The panel uses UpdatePanel to update its panel. 该面板使用UpdatePanel更新其面板。

<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). updatepanel每5秒钟刷新一次,这由Javascript函数触发(我知道System.Class.UI有计时器,但是由于某些原因我必须使用JS函数)。 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). 在后台代码上执行doPostBack ,我想将单选按钮值设置为数据库中的更新值,但UI没有任何更改(radiobutton值仍为1)。 The program will execute this function every 5 seconds (not from rbtnStatusDismissal_OnSelectedIndexChanged ). 程序将每5秒执行一次此功能(不是从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). 我尝试调试,然后将.SelectedValue设置为data.statusID的值(假设为5)。 But the radio button's value in UI still equals 1 (instead of 5). 但是,UI中单选按钮的值仍等于1(而不是5)。 What's wrong and what should I do? 怎么了,我该怎么办?

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 和这个js功能

<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. 如果您有任何问题而无法获得答案,请在评论中提问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 成功登录后,LoginStatus不会更改状态-ASP.NET C# - LoginStatus won't change status after a successful login - asp.net C# 我的RadioButtonList不会在回发后追加查询字符串或显示选定的值-C#和.Net - My RadioButtonList won't append Query String or show selected value after Postback - C# & .Net 带C#RadiobuttonList的ASP.net不会触发回发 - ASP.net w/ C# RadiobuttonList doesn't trigger a postback C# ASP.NET MVC:提交按钮后不会存储数据 - C# ASP.NET MVC : won't store data after submit button 动态更改asp.net中的单选按钮列表名称 - Dynamically change radiobuttonlist name in asp.net C# ASP.NET 复选框不会在数据库中更新 - C# ASP.NET Checkboxes won't update in Database 进程将无法在ASP.NET C#中启动 - Process won't start in ASP.NET C# OnServerValidate在ASP.Net C#中无法与PostBackUrl一起使用 - OnServerValidate Won't work with PostBackUrl in ASP.Net C# 在 asp.net C# 中第一次执行该事件后,如何让 RadioButtonList_SelectedIndexChanged 事件处理程序执行? - How do I get the RadioButtonList_SelectedIndexChanged event handler to execute after the first execution of that event in asp.net C#? 方法不会正确地为selectindex赋值,asp.net radiobuttonlist - method won't assign value to selectindex correctly, asp.net radiobuttonlist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM