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


相关推荐

  • Lena与图像处理

    Lena与图像处理在数字图像处理中,Lena(Lenna)是一张被广泛使用的标准图片,特别在图像压缩的算法研究中。(为什么用这幅图,是因为这图的各个频段的能量都很丰富:即有低频(光滑的皮肤),也有高频(帽子上的羽毛),很适合来验证各种算法)       然而,这张图片背后的故事是颇有意思的,很多人都抱有学究都是呆子的看法,然而Lena对此就是一个有力的驳斥。lena(lenna)是一张于19

    2022年6月19日
    28
  • 计算机图形学光栅化实验_光栅化算法

    计算机图形学光栅化实验_光栅化算法光栅化光栅化的任务将在投影变换中得到的正则立方体显示在屏幕上屏幕screen像素(pixels)的集合。屏幕的大小使用分辨率(resolution)来刻画。经典的光栅显示设备像素pixel像素是一个具有统一颜色的小立方体颜色由三部分组成red,green,blue屏幕空间​ 屏幕被划分成一个个正方体,称为像素。像素使用坐标(x,y)(x,y)(x,y)来表示,其中心是(x+0.5,y+0.5)(x+0.5,y+0.5)(x+0.5,y+0.5),

    2022年10月21日
    0
  • VScode 配置 Java 开发环境 (VSCode 天下第一!!!!!)

    VScode 配置 Java 开发环境 (VSCode 天下第一!!!!!)VScode配置Java环境1.下载JDK方式一:手动下载JDKOracleJavaSEAdoptOpenJdkAzulZuluforAzure-EnterpriseEdition方式二:VSCode中下载JDK按下Ctrl+Shift+P输入Java:ConfigureJavaRuntime2.添加JDK环境下面两种方式只…

    2022年6月8日
    54
  • java长轮询「建议收藏」

    java长轮询「建议收藏」在服务端向页面主动推送消息的业务场景下,有长轮训和websocket两种思路。springboot和websocket使用:https://blog.csdn.net/u014203449/article/details/102902078现在看看长轮询:设想一个业务场景:A用户打开页面,要求实时刷新数据,B用户操作新增数据,A页面刷新。1.页面长轮询的做法是,A用户打…

    2022年10月14日
    0
  • hdu 2838 Cow Sorting(树状数组)

    hdu 2838 Cow Sorting(树状数组)

    2022年1月21日
    41

发表回复

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

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