zoukankan      html  css  js  c++  java
  • 在GridView中增加LinkButton,出现错误:EnableEventValidation="false"

    错误信息:

    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();

     

     

  • 相关阅读:
    当我们开发一个接口时需要注意些什么
    一条查询语句在MySQL服务端的执行过程
    痞子衡嵌入式:基于恩智浦i.MXRT1060的MP4视频播放器(RT-Mp4Player)设计
    痞子衡嵌入式:基于恩智浦i.MXRT1010的MP3音乐播放器(RT-Mp3Player)设计
    《痞子衡嵌入式半月刊》 第 18 期
    痞子衡嵌入式:MCUBootUtility v2.4发布,轻松更换Flashloader文件
    华为HMS Core助力开发者打造精品应用,共创数智生活
    HMS Core 6.0即将发布 加码应用生态升级
    华为开发者联盟生态市场企业特惠GO第1期—应用软件专题
    卡片跳转快应用指定页面,如何点返回直接退出快应用回到卡片
  • 原文地址:https://www.cnblogs.com/blackbean/p/2734265.html
Copyright © 2011-2022 走看看