引起系统的按钮OnClick事件的重复器.无效的回发或回调参数
本文关键字:无效 回调 参数 系统 按钮 OnClick 事件 | 更新日期: 2023-09-27 18:18:04
我目前正在使用一个中继器来制作按钮列表。每个按钮都有一个on click事件,该事件将从列表中的重复器中删除该项目。然而,当我点击任何按钮时,我得到一个错误System.ArgumentException: Invalid postback or callback argument
。我在看这个答案。我不想禁用EnableEventValidation
(这样做有安全风险)。有没有更好的解决办法?
错误:
2014-08-13 12:52:34.305 7276 ASP.support_createcustomer_autocamerainstall_aspx Error Exception for url=/AdminDotNet/Support/CreateCustomer/AutoCameraInstall.aspx
System.ArgumentException: 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.
at System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
HTML: <asp:UpdatePanel ID="panelCameraGroup" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="locAddCameraButton" />
</Triggers>
<ContentTemplate>
<div id="divMainContent" runat="server">
<asp:Repeater ID="repeaterCameras" runat="server">
<ItemTemplate>
<div>
<asp:Button ID="locRemoveCameraButton" runat="server"
OnClientClick="return clickRemoveCamera(this)" OnClick="RemoveCamera"
Text="Remove" meta:resourcekey="btnRemoveCamera"
data-camera-position='<%# Eval("Position") %>'></asp:Button>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</ContentTemplate>
</asp:UpdatePanel>
clickRemoveCamera
只是一个空的JavaScript方法。locAddCameraButton
是一个按钮,用于添加到中继器列表中。我试过删除AsyncPostBackTrigger
和删除UpdateMode="Conditional"
。还是不行
:
protected void RemoveCamera(object sender, EventArgs e)
{
if (sender == null)
return;
Button removeCameraButton = (Button)sender;
string buttonClickPos = removeCameraButton.Attributes["data-camera-position"];
System.Diagnostics.Debug.WriteLine("buttonClickPos = " + buttonClickPos);
foreach (RepeaterCamera rc in repeaterCamerasList)
{
if(string.Equals(rc.Position.ToString(), buttonClickPos)){
System.Diagnostics.Debug.WriteLine("Found camera in repeater");
}
}
}
我明白了。在我的Page_Load
我改变了中继器。我应该只在!IsPostBack
期间这样做(我没有)。所以我添加了这个,它起作用了