现在的位置: 首页 > 综合 > 正文

在做GridView删除单条数据的时候,遇到的问题

2013年03月01日 ⁄ 综合 ⁄ 共 1228字 ⁄ 字号 评论关闭
    在做GidView删除单条数据,并弹出确认对话框得时候,遇到的一个百思不得其解的问题,下面先把错误贴在下面

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. 

很多时候都会遇到这个问题,其原因是验证回传的错误,有的时候把<%@ Page EnableEventValidation%>改成“false”就行乐,可是我还没有遇到在删除数据的时候遇到这个问题,下面是我的做法
我在GridVeiw中添加了一个<TemplateField>在他的<ItemTemplate>添加了一个Button,并在他的OnClientClick得添加了一段js代码,就是弹出对话框的代码,可是我在GridView得RowDeleting,写了删除代码,可是问题出来了,我在测试的时候,把断点放到RowDeleting上,可是当点击删除按钮的时候,不错,是弹出了一个对话框,可是他并没有给我执行RowDeleting事件,而是马上就出现上面的错误,我是百思不得其解。
  随后,我没有用<TemplateField>,而是我用的是GridView中的<CommandFile>得删除按钮(用的是Button),我在RowDataBound写了让<CommandFiled>中的按钮弹出对话框代码,继续测试,可是让我没有想到的是,他也给我 弹出对话框,可是也不执行RowDeleting事件,也不报错,我的脑袋又是一蒙,
  在网上找了找,没有找到解释这个错误的原因,不过到碰到过把<TemplateField>中的<ItemTemplate>中的Button改称LinkButton,我就把Button改成LinkButton,果然没有出错,也执行了RowDeleting
    问题是解决了,但是我还是没有弄明白是什么原因???

抱歉!评论已关闭.