加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 删除按钮 – 无效的回发或回调参数

发布时间:2020-12-16 00:19:08 所属栏目:百科 来源:网络整理
导读:我想在我的产品页面添加一个“删除”按钮,但我一直遇到这个错误的麻烦: 错误: Invalid postback or callback argument. Event validation is enabled using in configuration or %@ Page EnableEventValidation=”true” % in a page. For security purpos
我想在我的产品页面添加一个“删除”按钮,但我一直遇到这个错误的麻烦:

错误:

Invalid postback or callback argument. Event validation is enabled
using 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.

Stack Trace:

[ArgumentException: Invalid postback or callback argument. Event
validation is enabled using 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.]
System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId,
String argument) +8730646
System.Web.UI.Control.ValidateEvent(String uniqueID,String
eventArgument) +113
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +35
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl,String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)
+5563

我尝试过的:

在我的整个研究过程中,我了解到我可以使用enableEventValidation =“false”和validateRequest =“false”,但由于安全原因,我不建议这样做.
我试图将两者都设置为False,它修复了问题(我认为我没有插入DELETE查询),但是我对一些安全设置被关闭感到不舒服,只是为了摆脱错误.

我的转发器位于Page_Load内部,由于我使用的是母版页,因此转发器也处于一种形式.

ASPX:

<asp:Repeater runat="server" ID="RepProductMenu" OnItemCommand="RepProducts_ItemCommand">
<ItemTemplate>
         [Lots of stuff]......

        <asp:Button ID="BtnDelete" runat="server" Text="Delete" CommandName="Delete" CommandArguement='<%# Eval("ID") %>' /

</ItemTemplate>
</asp:Repeater>

Aspx.cs:

protected void RepProducts_ItemCommand(Object Sender,RepeaterCommandEventArgs e)
{
    if (e.CommandName == "Delete")
    {
        int ID = Int32.Parse(e.CommandArgument.ToString());
        // Add Delete Query
        Response.Write("COMMAND");
    }
}

任何建议和idéas表示赞赏.

解决方法

避免使用Delete作为CommandName,因为我相信这是保留的.

你的Button控件也有拼写错误. CommandArguement应该是CommandArgument

如果你的转发器在Page_Load被绑定而不是在@!(page.IsPostBack)里面,那么当点击删除按钮时它将被反弹.这可能会导致问题,因为在运行ItemCommand之前,转发器将会反弹.哪会使它无效.

尝试更改您的代码,以便在!(page.IsPostBack)包裹绑定时.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读