IPostBackEventHandler RaisePostBackEvent not triggered on asynchronous postback

asp.netasynchronouspostback

I have designed a custom user control, basically a button, that implements the IPostBackEventHandler interface, and obviously defines the RaisePostBackEvent(string eventArgument) method, where I do some processing, basically I trigger other events.

By default, when clicked my control will execute __doPostBack its client id for a full page refresh, and of course RaisePostBackEvent is triggered.

However, I want to be able the use the control to refresh an update panel, so from client side I use the __doPostBack method with the ID of the update panel and an additional argument.

The problem is that RaisePostBackEvent is not triggered. I know i could look in Page.Request.Params["__EVENTARGUMENT"] and do whatever I need, but I would really like something as simple and elegant as IPostBackEventHandler so as to have all the logic in my control.

Long story short, how can I trigger RaisePostBackEvent in case I have an asynchronous postback? Or is there another interface that with similar functionality?

Best Answer

The thing is (if I understand your question correctly) that the control that calls the __doPostBack must implement IPostBackEventHandler interface. So, for example if I have this markup in a usercontrol (that implements the IPostBackEventHander):

<asp:Button runat="server"
     UseSubmitBehavior="false" ID="Button"
     Text="Update"
     OnClientClick="myfunction();"/>

The myfunction javascript must look like this:

<script type="text/javascript">
    function myfunction(param)   
    {
        __doPostBack("<%= this.UniqueID %>", "myargs");    
    }
</script>

Notice that I send this.UniqueID and not the Button.UniqueID because the button does not implement IPostBackEventHander but the usercontrol does.