c# - 回发或回调参数无效。仅在图像按钮的情况下获取

标签 c# asp.net repeater eventvalidation

我收到以下错误:

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.

我有一个 ImageButtonRepeater像这样:

<asp:ImageButton ID="btn_CreatePdf" ImageUrl="~/images/download.png" 
                 ToolTip="Create Transmittal for this Contact" 
                 CommandName="CreatePdf"   
                 CommandArgument='<%#Eval("contactid")%>' runat="server" />

每当我点击这个 ImageButton ,它会导致该错误。

但是当我尝试 LinkButton而不是 ImageButton ,它工作正常。我尝试关注 LinkButton :

<asp:LinkButton ID="btn_CreatePdf" Text="Download" CommandName="CreatePdf" 
                CommandArgument='<%#Eval("contactid")%>' runat="server" >    
</asp:LinkButton>

请给我一个解决方案,为什么我只在 ImageButton 的情况下收到此错误? .

最佳答案

在您的页面加载 IsPostBack 检查

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        //your code here
    }
}

关于c# - 回发或回调参数无效。仅在图像按钮的情况下获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11095312/

相关文章:

c# - 同时建立多个蓝牙SPP

c# - 如何检查浏览器是否在网络应用程序中启用了 cookie?

javascript - 从 WCF 服务的 bool 方法接收答案

asp.net - 有人可以向我解释 asp.net 路由语法吗?

c# - 如何将单个 LINQ 对象绑定(bind)到 ASP.NET Repeater Control

html - 将行颜色添加到中继器中的奇数行

c# - 是否可以更改异步方法的任务创建选项?

c# - 创建 Intranet 站点

c# - IHostedService 的多种实现

c# - 在转发器控件中使用复选框