Solve LoadPostData Not Firing Problem

By | December 1, 2010

When you are developing a server side control and want to handle some postback data. You can implement the IPostBackDataHandler interface.

One issue I encountered is that the LoadPostData() method does not fire when the page posting back. Even if some values of textboxes are changed.

To solve this issue, you need to call the RegisterRequiresPostBack method of the Page to register your control, to tell the page that your control need to be trigger the LoadPostData method. Here’s the sample:

protected override void OnPreRender( EventArgs e )
{
    base.OnPreRender( e );

    if( Page != null )
        Page.RegisterRequiresPostBack( this );
}

That’s it. Enjoy! Smile