在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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • SpEL表达式总结

    SpEL表达式总结前言SpEL(SpringExpressionLanguage),即Spring表达式语言,是比JSP的EL更强大的一种表达式语言。为什么要总结SpEL,因为它可以在运行时查询和操作数据,尤其是数组列表型数据,因此可以缩减代码量,优化代码结构。个人认为很有用。目录一.用法1.@Value2.配置3.Expression​​​​​​二.表达式语法1…

    2022年9月12日
    3
  • 使用Pycharm运行TensorFlow,Virtualenv安装TensorFlow「建议收藏」

    使用Pycharm运行TensorFlow,Virtualenv安装TensorFlow「建议收藏」使用Pycharm运行TensorFlow,Virtualenv安装TensorFlow@(MachineLearningwithPython)系统:MacOS10.13本篇关注的是两个问题:通过virtualenv创建虚拟环境,并在此环境下安装TensorFlow在Pycharm下配置解释器,在Pycharm下运行训练代码Virtualenv+TensorflowTensorFl

    2022年8月26日
    6
  • web.xml中contextConfigLocation的作用

    web.xml中contextConfigLocation的作用在web.xml中通过contextConfigLocation配置spring,contextConfigLocation参数定义了要装入的Spring配置文件。1.在web.xml里配置需要加载的spring配置文件。  如果要装入多个配置文件,在<param-value>标记中用逗号作分隔符即可。<context-param>…

    2022年6月16日
    37
  • 根据/proc/partitions获取插入的U盘设备名称

    根据/proc/partitions获取插入的U盘设备名称1 在/proc/partitions中存放着U盘的设备名称,如sda,sdb2等,以sd开头。major主设备号,比如一个U盘有3个分区,主设备名为sda,major为8,分区的major也为8,minor则为分区号,sda1,sda2,minor值为1,2sda的minor为0,name即为设备名,连接/dev./设备名,就可以挂载到一个目录。blocks表示物理设备逻辑块

    2022年6月26日
    32
  • Linux history命令

    Linux history命令1、在脚本中由于是在另外一个shell中进行语句的执行,所以history显示的是脚本运行的shell的history语句,而不会显示你执行该脚本的终端中的history2、我们可以在家目录下的.bash_history文件中查看自己的历史命令,而history查看的是内存中的历史命令,如果需要将内存中的历史命令加入其中,那么就需要使用history-w将当前终端的历史命令覆盖.bash_history的内容或是history-a在.bash_history文件的尾部添加当前shell的历史命令

    2022年7月13日
    20
  • Spring Batch 之 Hello World教程

    Spring Batch 之 Hello World教程SpringBatch之HelloWorld教程本文我们基于springboot和springbatch实现一个简单helloworld入门批处理程序。如果你刚刚接触springbatch,这篇教程会让你花最短时间理解springbatch框架。SpringBatch框架介绍开始代码之前,我们先了解框架中的核心组件,见下图:批处理过程有Job组成,job是封装整…

    2022年5月27日
    27

发表回复

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

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