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


相关推荐

  • 2022保密教育线上培训考试 01[通俗易懂]

    2022保密教育线上培训考试 01[通俗易懂]试题1单选题1.机关、单位应当严格按照经过批准的范围对外提供涉密资料,并与外方签订(),限定涉密资料的使用和知悉范围。正确答案:B.保密协议2.按照公职人员政务处分法有关规定,有()行为造成不良后果或者影响的,予以警告、记过或者记大过;情节较重的,予以降级或者撤职;情节严重的,予以开除。正确答案:D.以上都正确3.下列关于涉密载体销毁的说法错误的是()。正确答案:B.涉密载体销毁的登记、审批记录无须保存4.保密期限是对国家秘密采取保密措施的时间要求。保密期限包括的形式有()。正

    2022年10月1日
    2
  • Lunix基本操作命令

    Lunix基本操作命令

    2022年10月3日
    5
  • C语言条件运算符_c语言数组长度可变吗

    C语言条件运算符_c语言数组长度可变吗如果希望获得两个数中最大的一个,可以使用if语句,例如:if(a>b){max=a;}else{max=b;}不过,C语言提供了一种更加简单的方法,叫做条件运算符,语法格式为:表达式1?表达式2:表达式3条件运算符是C语言中唯一的一个三目运算符,其求值规则为:如果表达式1的值为真,则以表达式2的值作为整个条件表达式的值,否则以表达式3…

    2022年10月4日
    4
  • webService接口服务端与客户端开发(入门级亲测可用)

    webService接口服务端与客户端开发(入门级亲测可用)webService接口服务端与客户端开发网上的有关webService的入门例子很多,但总是让新手云里雾里。看了本篇,如果对您有帮助,请随手一赞。。。经过尝试,发现以下内容:第一:webService服务端开发首先上图,一清二楚、以下weather包中有三种发布服务的方式;如果创建的是Java项目,Server类右键Java运行即可发布,但只能自己访问;如果想让别…

    2022年7月12日
    26
  • git 删除时报 the branch is not fully merged 这是什么意思

    git 删除时报 the branch is not fully merged 这是什么意思

    2021年10月23日
    110
  • c++中map遍历_怎么遍历map集合

    c++中map遍历_怎么遍历map集合C++结构化绑定声明在map容器遍历上的应用

    2025年11月29日
    5

发表回复

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

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