我正在使用 updatepanel 和一些触发器实现一个页面。
我要实现的内容如下。
Timer(timer1) 每隔 10 秒更新一次 UpdatePanel(update_content)。
如果用户处理 RadioButtonList(rbl_axis)、ListBox(list_point), 立即更新 UpdatePanel。
所有更新都是异步发生的。
这是我的代码。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" type="text/C#">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
div_title.InnerText= "Hello";
ScriptManager1.RegisterAsyncPostBackControl(rbl_axis);
ScriptManager1.RegisterAsyncPostBackControl(list_point);
printTime("Page_Load");
}
}
protected void printTime(string message)
{
div_content.InnerHtml += message +": "+ DateTime.Now.ToLongTimeString() + "<br />";
}
protected void Timer1_Tick(object sender, EventArgs e)
{
printTime("<font color='red'>Timer</font>");
}
protected void rbl_axis_SelectedIndexChanged(object sender, EventArgs e)
{
printTime("Axis("+rbl_axis.SelectedValue+")");
}
protected void list_point_SelectedIndexChanged(object sender, EventArgs e)
{
printTime(list_point.SelectedValue);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div>
<form id="form1" runat="server">
<asp:RadioButtonList ID="rbl_axis" runat="server" RepeatDirection="Horizontal"
OnSelectedIndexChanged="rbl_axis_SelectedIndexChanged">
<asp:ListItem Text="X" Value="X" Selected="True"></asp:ListItem>
<asp:ListItem Text="Y" Value="Y" ></asp:ListItem>
<asp:ListItem Text="Z" Value="Z" ></asp:ListItem>
</asp:RadioButtonList>
<asp:ListBox ID="list_point" runat="server" SelectionMode="Multiple" Width="100px" Height="100px"
OnSelectedIndexChanged="list_point_SelectedIndexChanged">
<asp:ListItem Text="Point1" Value="Point1"></asp:ListItem>
<asp:ListItem Text="Point2" Value="Point2"></asp:ListItem>
<asp:ListItem Text="Point3" Value="Point3"></asp:ListItem>
<asp:ListItem Text="Point4" Value="Point4"></asp:ListItem>
<asp:ListItem Text="Point5" Value="Point5"></asp:ListItem>
</asp:ListBox>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="10000"></asp:Timer>
<asp:UpdatePanel ID="update_content" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<div id="div_title" runat="server"></div>
<div id="div_content" runat="server"></div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</div>
</body>
</html>
它不能正常工作。
更新面板仅由计时器更新。
如果我处理列表框和单选按钮控件,更新面板不会更新。
并且在下一个 Timer Tick 时,应用列表框和单选按钮控件的修改。
我怎样才能实现我想要的。
你能给我一些建议吗?
先感谢您。