RegisterForEventValidation只能在渲染调用 [英] RegisterForEventValidation can only be called during Render

查看:212
本文介绍了RegisterForEventValidation只能在渲染调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WebMethod将从jQuery的AJAX调用:

I have a webmethod which will be called from jquery ajax:

[WebMethod]
public string TestMethod(string param1, string param2)
{
    StringBuilder b = new StringBuilder();
    HtmlTextWriter h = new HtmlTextWriter(new StringWriter(b));
    this.LoadControl("~/Pages/Controls/Listing.ascx").RenderControl(h);
    string controlAsString = b.ToString();
    return controlAsString;
}

(这是一个非静态方法,我们能够打它,这不是一个问题)

(it's a non-static method and we are able to hit it. That's not an issue)

在执行loadControl()方法中,我得到一个错误说:RegisterForEventValidation只能在所谓的渲染

When the loadControl() method is executed, I get an error saying: RegisterForEventValidation can only be called during Render.

我已经列入EnableEventValidation =当前的aspx假,禁用ViewState中也。但我仍然得到同样的错误。在这个任何想法?

I have already included EnableEventValidation="false" for the current aspx, disabled viewstate also. but still i get the same error. Any ideas on this?

推荐答案

解决办法是禁用页面的事件验证的搜索结果
 <%@页............ EnableEventValidation =假%GT;

Solution is to disable the Page's Event Validation as

<%@ Page ............ EnableEventValidation="false" %>

和通过添加下面的方法在C#code后面

and Override VerifyRenderingInServerForm by adding following method in your C# code behind

public override void VerifyRenderingInServerForm(Control control)
{
    /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
       server control at run time. */
}

请参考以下链接搜索结果
<一href=\"http://www.$c$cproject.com/Questions/45450/RegisterForEventValidation-can-only-be-called-duri\">http://www.$c$cproject.com/Questions/45450/RegisterForEventValidation-can-only-be-called-duri

这篇关于RegisterForEventValidation只能在渲染调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆