1

I'm implementing a page using updatepanel and some triggers.

What I want to implement is below.

  1. Timer(timer1) updates UpdatePanel(update_content) at intervals of 10 seconds.

  2. If User handle RadioButtonList(rbl_axis), ListBox(list_point), immediately update UpdatePanel.

  3. All update occurs by asynchronous.

Here is my code.

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

It doen't work properly.

Update Panel updates only by Timer.

If i handle the list box and radio button control, Update panel does't update.

And at the next Timer Tick, list box and radio button control's modification is applied.

How can I implement what i want.

Can you please give me some advice?

Thank you in advance.

4

1 に答える 1

1

ポストバックをトリガーするには、RadioButtonList と ListBox の両方で AutoPostBack プロパティを true に設定する必要があります。

また、Timer Click イベントで行ったのとほぼ同じ方法で、これらのポストバック イベントを UpdatePanel に登録する必要があります。

たとえば、コードは次のようになります。

<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>
于 2013-10-28T09:42:46.840 に答える