在GridView中增加LinkButton,出现错误:EnableEventValidation=”false”

在GridView中增加LinkButton,出现错误:EnableEventValidation=”false”错误信息:Invalidpostbackorcallbackargument.Eventvalidationisenabledusing<pagesenableEventValidation=”true”/>inconfigurationor<%@PageEnableEventValidation=”true”%>inapag…

大家好,又见面了,我是你们的朋友全栈君。

错误信息:

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.

代码:

 

<asp:GridView CssClass="GridView_Content" HeaderStyle-BackColor="#BBBBBB" 
                                    HeaderStyle-Font-Size="14px" ID="grvUserACL" AllowSorting="True" runat="server" 
                                        AutoGenerateColumns="False" Width="100%"
                                        onrowdatabound="grvUserACL_RowDataBound" OnRowCommand="grvUserACL_RowCommand" >
                                    <Columns>                                        
                                        <asp:TemplateField HeaderText="Server Set">                                            
                                            <ItemTemplate>
                                                <asp:Label runat="server" Text='<%# Eval("SetID") %>' ID="SetID"></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                         
                                        <asp:TemplateField HeaderText="UserSingleClick" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol"> <ItemTemplate> <asp:LinkButton ID="UserSingleClick" CommandName="UserSingleClick" Text="UserSingleClick" runat="server"></asp:LinkButton> </ItemTemplate> </asp:TemplateField>                                                                                                             
                                    </Columns>
                                    <EmptyDataTemplate>
                                        No data
                                    </EmptyDataTemplate>
                                    <HeaderStyle BackColor="#BBBBBB" Font-Size="14px"></HeaderStyle>
                                </asp:GridView>

 

 

protected void grvUserACL_RowDataBound(object sender, GridViewRowEventArgs e)
        {           
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "if(this.style.backgroundColor!='peachpuff'){this.style.backgroundColor='#Efefef'}");//当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseout", "if(this.style.backgroundColor!='peachpuff'){this.style.backgroundColor='#e4ecf2'}");//当鼠标移开时还原背景色
                //e.Row.Attributes.Add("onclick", "selectSubGVIndex(this," + e.Row.RowIndex.ToString() + ")");

                // 从第一个单元格内获得LinkButton控件
                LinkButton _singleClickButton = (LinkButton)e.Row.Cells[9].FindControl("UserSingleClick");
                if (_singleClickButton != null)
                {
    
    
            //增加以下代码解决问题,EnableEventValidation="false" _singleClickButton.CommandArgument
= e.Row.RowIndex.ToString(); } // 返回一个字符串,表示对包含目标控件的 ID 和事件参数的回发函数的 JavaScript 调用 string _jsSingle = ClientScript.GetPostBackClientHyperlink(_singleClickButton, ""); _jsSingle = "selectSubGVIndex(this," + e.Row.RowIndex.ToString() + ");" + _jsSingle; e.Row.Attributes["onclick"] = _jsSingle; } }

解决方法:
需给Linkbutton的属性CommandArgument定义一个不同的值。
_singleClickButton.CommandArgument
= e.Row.RowIndex.ToString();

 

 

转载于:https://www.cnblogs.com/blackbean/archive/2012/10/22/2734265.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/159205.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • linux切换java版本_java_home environment variable

    linux切换java版本_java_home environment variable© 版权声明:本文为博主原创文章,转载请注明出处本文根据官方文档加上自己的理解,仅供参考官方文档:https://docs.spring.io/spring-security/

    2022年8月4日
    6
  • vue-router 详解

    vue-router 详解文章目录1、认识vue-router2、安装和使用vue-router1、认识vue-router目前前端流行的三大框架,都有自己的路由实现:Angular的ngRouterReact的ReactRouterVue的vue-routervue-router是Vue.js官方的路由插件,它和vue.js是深度集成的,适合用于构建单页面应用。我们可以访问其官方网站对其进行学习:https://router.vuejs.org/zh/vue-router是基于路由和组件的路由用户设定访问

    2022年7月11日
    24
  • idea激活码地址3月最新在线激活

    idea激活码地址3月最新在线激活,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月14日
    136
  • 猴子摘香蕉问题c语言_c语言人工智能算法

    猴子摘香蕉问题c语言_c语言人工智能算法问题说明:房间内有一只猴子,一个箱子和一个挂在天花板上的香蕉。三者的位置如下图所示:初始状态:三者在输入的初始位置,猴子手上无香蕉,猴子不在箱子上。目标状态:三者均在香蕉对应的位置,猴子手上有香蕉,且在箱子上。实现步骤:猴子走到箱子处猴子将箱子推到香蕉处猴子爬上箱子猴子摘香蕉程序内容:本程序主要实现猴子摘香蕉的过程,即从初始状态到目标状态。程序运行后,根据用户输入的三者的位置,按照实现步骤更新每一过程后的状态变量,并将过程输出。本程序使用以下函数:main():主函数

    2022年9月26日
    3
  • 矩阵的行列式、秩的意义

    矩阵的行列式、秩的意义线性代数真是一个很抽象的东西,即使我们很多人都学过,但是我相信绝大部分的都不知道这是干嘛用的,找了不少资料,终于发现了这么一篇好文章,于是强烈希望可以和大家分享,帮助大伙进一步理解矩阵的行列式和秩的本质意义。1关于面积:    一种映射 大家会说,面积,不就是长乘以宽么,其实不然。我们首先明确,这里所讨论的面积,是欧几里得空间几何面积的基本单位:平行四边形的面积。平行四边形面积

    2022年5月8日
    51
  • 【C 语言】文件操作 ( fopen 文件打开方式详解 )「建议收藏」

    【C 语言】文件操作 ( fopen 文件打开方式详解 )「建议收藏」r:只读方式打开文件,文件必须存在;文件不存在打开失败;+:读写方式打开文件;w:打开只写文件,文件不存在创建文件,文件存在覆盖文件;a:打开只写文件,文件不存在创建文件,文件存在追加文件;

    2022年7月13日
    18

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号