Solve LoadPostData Not Firing Problem

by Weijie JIN on

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

  • marty

    Hi Jin,

    The NodeDepth property is always return -1. How to resolve it?

  • http://jinweijie.myopenid.com/ jinweijie

    Hi,

    I’ve replied you by email.

    Weijie

Previous post:

Next post: