se the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation

僤鯓⒐⒋嵵緔 提交于 2019-12-05 05:51:30

The problem with ASP.NET 2.0 event validation is that it is all or nothing and a bit heavy handed. I read an article that explains what you should do here.

Basically you need to register the child controls of the user control with the event validation engine.

C#
protected override void Render(HtmlTextWriter writer)
{
    // Register controls for event validation
    foreach (Control c in this.Controls)
    {
        this.Page.ClientScript.RegisterForEventValidation(
                c.UniqueID.ToString()
        );
    }
    base.Render(writer);
}

VB
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

    For Each aControl As Control In Me.Controls
        Me.Page.ClientScript.RegisterForEventValidation(aControl.UniqueID.ToString)
    Next aControl

    MyBase.Render(writer)
End Sub

Now this may not solve your problem because I am not sure how you are returning the string. Another article explains that the event validation is a combination of the control's unique ID and all the values it can pass back. If you are using the command value of a button to pass the text you may have trouble with this task.

If the event that is causing the issue is the click, then registering the controls of the user control should do the trick.

Mahmoud

try

if (!Page.IsPostBack)

before load and bind data in datagrid

In my situation I was trying to update a GridViews datasource on page_load and I forgot to check if the request was a postback, thus my source was trying to change and it threw this error. Once I did the check for post back it worked fine. Hope this helps someone in the future.

    if (Page.IsPostBack == false)
    {
        this.sqlObj = new SqlServer(ConfigurationManager.ConnectionStrings["PdfReceiverConnectionString"].ToString());
        this.populateDataGrid();
    }

You can leave it enabled then register your control for event validation. Add the following call in the PreRender or Render page life cycle then your control should work without having to turn off eventValidation:

  Page.ClientScript.RegisterForEventValidation(this.UniqueID);

Check your HTML, nested from Tags will also cause that

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!