ASP.NET多重触发无法正常工作

用户名

我正在使用updatepanel和一些触发器实现页面。

我要实现的内容如下。

  1. Timer(timer1)每隔10秒更新一次UpdatePanel(update_content)。

  2. 如果用户处理RadioButtonList(rbl_axis),ListBox(list_point),请立即更新UpdatePanel。

  3. 所有更新都是通过异步进行的

这是我的代码。

<%@ 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>

它不能正常工作。

更新面板仅按计时器更新。

如果我处理列表框和单选按钮控件,则“更新”面板不会更新。

在下一个“计时器滴答”中,将应用列表框和单选按钮控件的修改。

如何实现我想要的。

你能给我一些建议吗?

先感谢您。

塔索斯(Tasos K.)

您的RadioButtonList和ListBox都必须将AutoPostBack属性设置为true才能触发回发。

另外,您需要将这些回发事件注册到UpdatePanel,几乎就像使用Timer Click事件一样。

例如,您的代码可能更像这样:

<asp:RadioButtonList ID="rbl_axis" runat="server" RepeatDirection="Horizontal"
     OnSelectedIndexChanged="rbl_axis_SelectedIndexChanged" AutoPostBack="true">
    <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"
    AutoPostBack="true">
    <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:UpdatePanel ID="update_content" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
        <asp:AsyncPostBackTrigger ControlID="rbl_axis" EventName="SelectedIndexChanged" />
        <asp:AsyncPostBackTrigger ControlID="list_point" EventName="SelectedIndexChanged" />
    </Triggers>
    <ContentTemplate>
        <div id="div_title" runat="server"></div>
        <div id="div_content" runat="server"></div>
    </ContentTemplate>
</asp:UpdatePanel>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在asp.net中触发Updatepanel后,Javascript无法正常工作

来自分类Dev

asp.net WebMethod无法正常工作

来自分类Dev

asp .net中的UserControl无法正常工作?

来自分类Dev

ASP .NET ID SetSetwordHashAsync无法正常工作

来自分类Dev

分页在ASP.NET MVC 5中无法正常工作

来自分类Dev

ASP.NET Web API和Ninject无法正常工作

来自分类Dev

MySQL asp.net字符集无法正常工作

来自分类Dev

CSS对于ASP.Net按钮无法正常工作

来自分类Dev

Asp.Net下拉菜单无法正常工作

来自分类Dev

asp.net中的jQuery示例无法正常工作

来自分类Dev

ASP.Net Core CookieRequestCultureProvider无法正常工作

来自分类Dev

ASP.NET Core MVC Ajax无法正常工作

来自分类Dev

ASP.NET Core 5.0 RequestSizeLimit无法正常工作

来自分类Dev

ASP.NET MVC循环似乎无法正常工作

来自分类Dev

asp.net中的ImageButton的onclick无法正常工作

来自分类Dev

多语言ASP.NET网站无法正常工作

来自分类Dev

ASP.NET处理程序无法正常工作

来自分类Dev

CustomValidator在asp.net中无法正常工作

来自分类Dev

Asp.Net:TableSorter更新后无法正常工作

来自分类Dev

锚标记在asp.net中无法正常工作

来自分类Dev

我的ASP.NET DropDownList无法正常工作

来自分类Dev

TryUpdateModel Asp.Net MVC无法正常工作

来自分类Dev

无法正常工作SaveChanges()方法ASP.NET MVC

来自分类Dev

Regexvalidator 的 validaterequestmode=enabled 在 asp.net 中无法正常工作

来自分类Dev

Asp.net 核心删除按钮无法正常工作

来自分类Dev

ASP日历无法正常工作

来自分类Dev

ASP登录无法正常工作

来自分类Dev

经典ASP #include虚拟无法正常工作

来自分类Dev

CDO经典ASP表单无法正常工作