同一个gridview中,点击查看时,rowcommand正常运行。
而点击编辑和删除时出现错误:
回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件设置了EnableEventValidation= "false"以后到时不出现错误了,但是页面不执行任何操作。设置了断点查看,发现rowcommand事件没有执行,有遇到相同问题的给个答案吧?-----------------
在线结贴,诚信模范!

解决方案 »

  1.   

    你是不是在客户端修改了GridView的内容?错误信息里都说了:此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。
    如果在客户端修改了内容,那么就会报这个错。
      

  2.   

    <asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                          BackColor="White" BorderColor="#C0C9D0" BorderStyle="Solid" BorderWidth="1px"
                          CellPadding="3" CssClass="font12px" EmptyDataText="---------------------没有数据-------------------"
                          GridLines="Vertical" OnRowCommand="GridView2_RowCommand" OnRowDataBound="GridView2_RowDataBound"
                          PageSize="5" UseAccessibleHeader="False" Width="100%" OnRowEditing="GridView2_RowEditing" OnPageIndexChanging="GridView2_PageIndexChanging">
                    <PagerSettings Visible="False" />
                    <footerstyle BackColor="#CCCCCC" ForeColor="Black" />              
                    <RowStyle BackColor="White" ForeColor="Black" />
                    <columns>
                    <asp:TemplateField HeaderText="序号">
                      <itemtemplate> <%#  Container.DataItemIndex+1 %> </itemtemplate>
                      <headerstyle BorderColor="Transparent" Font-Bold="False" HorizontalAlign="Center" />              
                      <itemstyle BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center"
                                      Width="50px" />              
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="名称">
                      <itemtemplate>
                        <asp:LinkButton ID="lkBT" runat="server" CommandArgument='<%# Eval("QSTCODE") %>'
                                          CommandName="ShowDetails" CssClass="whgl_link" Text='<%# Eval("QUESTION")%>'></asp:LinkButton>
                      </itemtemplate>
                      <headerstyle BorderColor="Transparent" Font-Bold="False" HorizontalAlign="Center" />              
                      <itemstyle BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Left"/>             
                    </asp:TemplateField>
                    <asp:BoundField DataField="Difficulty" HeaderText="难度">
                      <headerstyle BorderColor="Transparent" Font-Bold="False" HorizontalAlign="Center" />              
                      <itemstyle BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center"/>    
                      </asp:BoundField>
                    <asp:BoundField HeaderText="认知度" DataField="LEVELOFCOGNIZING">
                      <headerstyle BorderColor="Transparent" Font-Bold="False" HorizontalAlign="Center" />              
                      <itemstyle BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center"/>    
                      </asp:BoundField>
                    <asp:BoundField HeaderText="题型" DataField="TYPEOFQUESTION">
                      <headerstyle BorderColor="Transparent" Font-Bold="False" HorizontalAlign="Center" />              
                      <itemstyle BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center"/>    
                      </asp:BoundField>
                    <asp:BoundField HeaderText="分值" DataField="GRADE">
                      <headerstyle BorderColor="Transparent" Font-Bold="False" HorizontalAlign="Center" />              
                      <itemstyle BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center"/>    
                      </asp:BoundField>
                    <asp:BoundField HeaderText="试题范围" DataField="HSE">
                      <headerstyle BorderColor="Transparent" Font-Bold="False" HorizontalAlign="Center" />              
                      <itemstyle BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center"/>    
                      </asp:BoundField>
                    <asp:BoundField HeaderText="HSE属性" DataField="PROPERTY">
                      <headerstyle BorderColor="Transparent" Font-Bold="False" HorizontalAlign="Center" />              
                      <itemstyle BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center"/>    
                      </asp:BoundField>
                    <asp:BoundField DataField="ENABLED" HeaderText="是否可用" HtmlEncode="False">
                      <headerstyle BorderColor="Transparent" Font-Bold="False" />              
                      <itemstyle BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" Width="50px" />
                    </asp:BoundField>
                    <asp:TemplateField HeaderText="修改">
                      <itemtemplate>
                        <asp:ImageButton ID="btnDetails" runat="server" AlternateText="编辑" CommandArgument='<%# Eval("QSTCODE") %>' CommandName="EditData" ImageUrl="~/Image/eidt.gif" />                                </itemtemplate>
                      <headerstyle BorderColor="Transparent" Font-Bold="False" HorizontalAlign="Center" />              
                      <itemstyle BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center"
                                      Width="50px" />              
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="删除">
                      <itemtemplate>
                        <asp:ImageButton ID="lkbtnDelete" runat="server" AlternateText="删除" CommandArgument='<%# Eval("QSTCODE") %>'
                                          CommandName="del" ImageUrl="~/Image/bt_del.gif" onclientclick="return confirm('确认要删除?')" />                                </itemtemplate>
                      <headerstyle BorderColor="Transparent" Font-Bold="False" HorizontalAlign="Center" />              
                      <itemstyle BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center"
                                      Width="50px" />              
                    </asp:TemplateField>
                    </columns>
                    <pagerstyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />              
                    <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                    <headerstyle CssClass="GridView_head" Font-Bold="True" ForeColor="Black" Height="25px" />              
                    <EditRowStyle HorizontalAlign="Center" />
                    <AlternatingRowStyle BackColor="WhiteSmoke" BorderColor="White" BorderStyle="Solid"
                              BorderWidth="1px" />
                  </asp:GridView>    protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            String ComA = e.CommandArgument.ToString();
            if (e.CommandName == "del")
            {
                DeleteData(ComA);
            }
            if (e.CommandName == "EditData")
            {
                this.tableTK_1.Visible = true;
                SetUnReadOnly2();
                ShowDetail(ComA);
            }
            if (e.CommandName == "ShowDetails")
            {
                this.tableTK_1.Visible = true;
                SetReadOnly2();
                ShowDetail(ComA);
            }
        }
      

  3.   

    感觉你应该把CommandName换一下,别和默认的一样哦````
      

  4.   

    换了也没用,另外我没有修改gridview的内容。
    关键在于点击“名称”时,正常执行了rowcommand;而点击编辑图标时,根本没执行就出现错误了。
      

  5.   

    稀奇,编辑和"名称"所作的一样的东西也会出现这问题````````
    那把编辑的commandname换成ShowDetails什么情况呢?
      

  6.   

    <asp:TemplateField HeaderText="删除">
                      <itemtemplate>
                        <asp:ImageButton ID="lkbtnDelete" runat="server" AlternateText="删除" CommandArgument='<%# Eval("QSTCODE") %>'
                                          CommandName="del" ImageUrl="~/Image/bt_del.gif" onclientclick="return confirm('确认要删除?')" />                                </itemtemplate>
                      <headerstyle BorderColor="Transparent" Font-Bold="False" HorizontalAlign="Center" />              
                      <itemstyle BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center"
                                      Width="50px" />              
                    </asp:TemplateField>
    ---------------
    SetUnReadOnly2();
                ShowDetail(ComA);
    这两个函数的问题?????
      

  7.   

    页面具体情况是这样的,左边是个treeview(共3级),点击到treeview的末节点后右边的页面出现gridview,然后可以添加、修改、删除和查看。
    添加正常,查看正常(查看就是点击名称,然后再gridview下面出现查看界面),执行完了gridviewdatabind()后继续执行了rowcommand。
    点击编辑用的也是查看的界面(只不过文本框可用了,增加了按钮保存和取消),这时候就出现如一楼诉说的错误,经查执行了gridviewdatabind()后未执行rowcommand就直接出现了错误。
      

  8.   

    SetUnReadOnly2(); 
    ShowDetail(ComA); 
    这两个函数的问题?????
    =============================
    这两个函数还没有执行就报错了,showdetail(coma)在查看时执行过应该也没有问题。