UpdatePanel触发错误。在UpdatePanel中未找到与触发器关联的控件的事件。

4

我在使用 ASP.NET WebForms 中的 asp:UpdatePanel 和 Trigger 时遇到了问题。Trigger 找不到 UpdatePanel 上的事件。我看过很多示例并复制了它们的实现,但无法正确实现。我对 WebForms 完全是新手,请帮忙解决。谢谢。

                <tr>
                    <td class="label1">Will use ETL?</td>
                    <td>
                        <asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="updatePanel1">
                            <ContentTemplate>
                                <asp:RadioButtonList ID="useEtl" runat="server" RepeatDirection="Horizontal" Width="120" OnSelectedIndexChanged="useEtl_SelectedIndexChanged">
                                    <asp:ListItem Text="Yes" Value="1" />
                                    <asp:ListItem Text="No" Value="0" />
                                </asp:RadioButtonList>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </td>
                    <td class="label1">ETL Box</td>
                    <td>
                        <asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="updatePanel2">
                            <ContentTemplate>
                                <asp:TextBox ID="etlBox" runat="server"/>
                            </ContentTemplate>
                            <Triggers>
                                 <asp:AsyncPostBackTrigger ControlID="useEtl" EventName="OnSelectedIndexChanged" />
                             </Triggers>
                        </asp:UpdatePanel>
                    </td>
                </tr>

通过Sujith的解决方案(将EventName更改为SelectedIndexChanged),我添加了AutoPostBack="true"以更新updatePanel1。神奇的是,它完美地工作了! - apacheix
2个回答

7
将您的代码更改如下:
<asp:AsyncPostBackTrigger ControlID="useEtl" EventName="SelectedIndexChanged" />

你提到的事件名称是错误的,所以它无法工作。你也可以尝试使用以下代码实现相同的功能。
UpdatePanel1.Triggers.Add(new AsyncPostBackTrigger()
{
    ControlID = useEtl,
    EventName = "SelectedIndexChanged", // this may be optional
}

1
嗨,Sujith,我尝试将其更改为SelectedIndexChanged,但这还不够。useEtl_SelectedIndexChanged没有被调用。但好消息是,它不再有错误了。谢谢。 - apacheix

0
td>
                        <asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="updatePanel1">
                            <ContentTemplate>
                                <asp:RadioButtonList ID="useEtl" runat="server" RepeatDirection="Horizontal" AutoPostBack="true" Width="120" OnSelectedIndexChanged="useEtl_SelectedIndexChanged">
                                    <asp:ListItem Text="Yes" Value="1" />
                                    <asp:ListItem Text="No" Value="0" />
                                </asp:RadioButtonList>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </td>
                    <td class="label1">ETL Box</td>
                    <td>
                         <asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="updatePanel2">
                            <ContentTemplate>
                                <asp:TextBox ID="etlBox" runat="server" Enabled="false"/>
                            </ContentTemplate>
                           <Triggers>
                                 <asp:AsyncPostBackTrigger ControlID="useEtl" EventName="SelectedIndexChanged" />
                             </Triggers>
                        </asp:UpdatePanel>
                    </td>

我在RadioButtonList和updatepanel方面遇到了同样的问题。 - drzounds
可能是一个已知的错误,基于 https://forums.asp.net/t/1015714.aspx?RadioButtonList+SelectedIndexChanged+as+UpdatePanel+Trigger - drzounds

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接