首页 新闻 会员 周边

ASP.NET中 listiview 里面绑定button 怎么才能触发button的事件?

0
[已解决问题] 解决于 2010-08-21 16:47

<asp:ListView runat="server">

        <ItemTemplate>

            <table border="0" cellpadding="0" cellspacing="0">

                <tr>

                    <td>

                        <asp:Button Text="text" runat="server" />

                    </td>

                    <td>

                        <asp:Label Text="text" runat="server" />

                    </td>

                </tr>

            </table>

        </ItemTemplate>

    </asp:ListView>

每次点击button 总是提示“

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

而且 itemcommond事件也没有触发

烟霞的主页 烟霞 | 初学一级 | 园豆:166
提问于:2010-08-10 11:00
< >
分享
最佳答案
0

根据提示,说明回发中有HTML字符,需要在当前页的Page属性增加enableEventValidation="false".

Astar | 高人七级 |园豆:40805 | 2010-08-10 11:09
这个我也试了 但是也不执行lvLayout_ItemCommand事件
烟霞 | 园豆:166 (初学一级) | 2010-08-10 11:11
@烟霞:没见你发的代码asp:ListView上有lvLayout_ItemCommand这个事件呀。
Astar | 园豆:40805 (高人七级) | 2010-08-10 11:16
private static void NewMethod(ListViewItemEventArgs e) { Button btnTest = e.Item.FindControl("btnReplay") as Button; TextBox tbTest = e.Item.FindControl("tbMessageBox") as TextBox; Label lbTest = e.Item.FindControl("lbIssueUser") as Label; if (btnTest.CommandName == "btnClick") { tbTest.Text = "回复" + lbTest.Text + ":"; } } protected void lvLayout_ItemCommand(object sender, ListViewCommandEventArgs e) { TextBox tb = this.FindControl("tbMessageBox") as TextBox; Label lb = this.FindControl("lbIssueUser") as Label; if (!IsPostBack) { if (e.CommandName == "btnClick") { tb.Text += lb.Text; } } } 这是这两个绑定的事件 上面的数据绑定能执行 但下面的lvLayout_ItemCommand事件 怎么都不执行 刚才又用了楼下说的ValidateRequest="false" 也是不行
烟霞 | 园豆:166 (初学一级) | 2010-08-10 11:19
其他回答(2)
0

在<%Page %>中加上EnableEventValidation="false"

如果还不行再增加一个 ValidateRequest="false"属性

主要是防止有HTML标记等恶意代码

kyo-yo | 园豆:5587 (大侠五级) | 2010-08-10 11:11
这个试过了 就是不执行我的代码段
支持(0) 反对(0) 烟霞 | 园豆:166 (初学一级) | 2010-08-10 11:20
0

把

<asp:Button Text="text" runat="server" />

改成:

<asp:Button Text="text" runat="server" CausesValidation="false"/>

HUHU慈悲 | 园豆:9973 (大侠五级) | 2010-08-10 11:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册