在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 开启allow_url_fopen,如何开启allow_url_fopen函数[通俗易懂]

    linux 开启allow_url_fopen,如何开启allow_url_fopen函数[通俗易懂]有些程序比如dede和discuz,都会有需要打开这个函数,不打开这个函数的甚至无法安装!如何解决这个问题呢?这里给出打开这个函数的终极解决办法:1.首先确保你拥有服务器的操作权限,如果只是虚拟空间客户,那么你就联系主机商帮助操作吧;2.打开PHP的配置文件php.ini,如果你的主机是win2003该文件在C:\WINDOWS目录下,直接用记事本打开就可以,如果是apache那么就是在你的php…

    2022年7月16日
    21
  • Idea激活码永久有效Idea2021.1.2激活码教程-持续更新,一步到位

    Idea激活码永久有效Idea2021.1.2激活码教程-持续更新,一步到位Idea激活码永久有效2021.1.2激活码教程-Windows版永久激活-持续更新,Idea激活码2021.1.2成功激活

    2022年6月17日
    72
  • 网口转串口线(console线)制作「建议收藏」

    网口转串口线(console线)制作「建议收藏」console线RJ45转串口9孔:短距离使用时连接RXD、TXD、GND线即可。

    2022年4月19日
    747
  • linux的rwx权限,linux权限管理:rwx

    linux的rwx权限,linux权限管理:rwx标签:rwx权限管理简介:r,w,x对文件及目录进行权限管理,从而达到文件及目录管理。1、rwx对于文件而言:r:可读,可以使用类似cat等命令查看文件内容;w:可写,可以编辑或删除此文件;x:可执行,exacutable,可以命令提示符下当作命令提交给内核运行;2、rwx对于目录而言:r:可以对此目录执行ls以列出内部的所有文件;w:可以在此目录创建文件;x:可以使用cd切换进此目录,也可以使用…

    2022年6月10日
    65
  • matlab中plot函数的功能及用法_plot绘制什么图

    matlab中plot函数的功能及用法_plot绘制什么图使用plot绘制二维图像本文转自http://blog.sina.com.cn/s/blog_d8f783c90102woqb.html以及https://blog.csdn.net/alvern_zhang/article/details/51153058MATLAB中plot函数常常被用于绘制各种二维图像,其用法也是多种多样,本文仅介绍plot函数的基本用法——使用plot函数绘制二维点图和线…

    2022年10月16日
    3
  • can not create this interface_getinterfaces方法

    can not create this interface_getinterfaces方法Androidstudio导入依赖,构建时报错错误如下: StaticinterfacemethodsareonlysupportedstartingwithAndroidN(–min-api24):voidbutterknife.Unbinder.lambda$static$0()Message{kind=ERROR,text=Statici…

    2025年8月31日
    7

发表回复

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

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