views:

2083

answers:

1

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?

+1  A: 

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.

Johan Leino
The thing is that in the control I have an update panel and through an asynchronous postback I have to update just the content of the update panel so in my javascript function I say `__doPostBack("updatePanelID", "myargs");` and the method `RaisePotsBackEvent` is never called, even though my control implements the `IPostBackEventHandler` interface.
iulianchira
But UpdatePanel does not implement IPostBackEventHandler, or am I missing something? So you can´t send the Id of the UpdatePanel as the first argument to __DoPostBack(...) you have to send the Id of your control and also the Unique (namingcontainer id) of that control.
Johan Leino