[英]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.