【问题标题】:Button postback getting error按钮回发出现错误
【发布时间】:2014-10-04 10:32:02
【问题描述】:

我有一个更新面板,里面有一个列表视图。此面板每隔 10 秒刷新一次,并且更新并重新绑定列表视图源。我的列表视图有一些图像按钮,问题就来了。当我单击任何列表视图按钮时,出现错误:

“无效的回发或回调参数。”错误。

我正在尝试我在搜索结果中看到的所有内容,不,我不会将验证设置为 false。

这是我的列表的简化模板。

<asp:UpdatePanel runat="server" ID="pnlRegistro" ClientIDMode="Static" OnLoad="pnlRegistro_Load">
    <ContentTemplate>
        <asp:ListView runat="server" ID="lvRegistro" OnPreRender="lvRegistro_PreRender" >
            <LayoutTemplate>
                <!-- Unread notification count -->
                <span runat="server" id="spanRegistroCount" class="mws-dropdown-notif">
                    <asp:Label ID="lblRegistroCount" runat="server" Text="0"></asp:Label>
                </span>
            </LayoutTemplate>
            <ItemTemplate>
                <li class="<%# Convert.ToInt32(Eval("RegistroHorarioId"))==0?"read":"unread"%>">
                    <a>
                        <div style="width: 80%; float: left;">
                            <span class="message" <%#Eval("SpanColor")%>>
                                <%#Eval("Status")%>
                            </span>
                        </div>
                        <div style="float: right">
                            <asp:ImageButton runat="server" ID="btnRegistro" OnClick="btnRegistro_Click"/>
                        </div>
                    </a>
                </li>
            </ItemTemplate>
        </asp:ListView>
    </ContentTemplate>
</asp:UpdatePanel>

如何解决此错误并触发 "btnRegistro_Click" 事件?

【问题讨论】:

    标签: c# asp.net button postback


    【解决方案1】:

    更新面板用于更新部分页面,而不是进行完整的回发。

    因此,您必须添加 PostBackTrigger 同步或异步任何您想要的,因为您正在使用更新面板并且更新面板事件在触发器中定义以避免完全回发,所以很可能您想要 asnc 回发触发。

    在内容模板结束标记(&lt;/ContentTemplate&gt;)之后添加按钮事件触发器:

     </ContentTemplate>
     <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="btnRegistro" EventName="Click" /> 
    </Triggers>
    </asp:UpdatePanel>
    

    您还应该阅读Understanding ASP.NET AJAX UpdatePanel Triggers

    【讨论】:

    • 添加此触发器时,我收到此错误:“在 UpdatePanel 'pnlRegistro' 中找不到触发器的 ID 为 'btnRegistro' 的控件。”所以我尝试使用 ListView 中的 onItemCommand 并添加 ItemCommand 触发器,但我得到“无效的回发或回调参数”。再次。有什么想法吗?
    • 我不知道 LIstView 工作,但错误的主要原因是没有添加触发器
    猜你喜欢
    • 2021-09-14
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-17
    • 1970-01-01
    相关资源
    最近更新 更多