views:

3224

answers:

4

I have a rather complex custom control - the custom control has a couple of update panels in it.

I am trying to use the control like this inside of an update panel:

    <asp:UpdatePanel ID="up1" runat="server">
    <ContentTemplate>
     <asp:Button ID="btn1" runat="server" Text="Sample Button" />&nbsp;&nbsp;<asp:Label ID="lblTime" runat="server"></asp:Label>    
     <cc1:MyCustomControl ID="MyCustomControl1" runat="server" >
    </cc1:MyCustomControl>
    </ContentTemplate>
</asp:UpdatePanel>

When I click the button in the update panel, it does an async post back and there is no screen "flicker" When I click a button in my custom control the page flickers and does a full post back.

Inside the custom control, there are update panels that are trying to do full postbacks (based on triggers).

How can I make the page level UpdatePanel not do a full postback no matter what is going in inside of the custom control?

A: 

On the UpdatePanel, set the property ChildrenAsTriggers="true". This tells the UpdatePanel to intercept all PostBack invocations that originate from inside the UpdatePanel.

You may want to also explore the UpdateMode property, which determines what kinds of events trigger an update. (By default, an UpdatePanel will refresh if any other panel on the screen gets refreshed. This threw me for awhile until I realized what was going on.)

Rex M
This did not work, it only impacts "immediate child controls" according to the MSDN docs. I think the issue is with controls that are nested within the Custom Control causing a postback.
brendan
A: 

I would first look if there is some other issue with the custom control causing the full page postback, as in any case what should be happening is that the whole update panel refreshes (still with ajax).

After that, just look at the Nesting UpdatePanel Controls section of this: http://msdn.microsoft.com/en-us/library/bb398867.aspx#

Also make sure to have the ScriptManager control with the property EnablePartialRendering set to true.

eglasius
A: 

Have you thought about explicitly setting an asp:AsyncPostBackTrigger with the btn1 control in the up1 UpdatePanel control.

<asp:UpdatePanel ID="up1" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btn1" EventName="Click" />
    </Triggers>
    <ContentTemplate>     
        <asp:Button ID="btn1" runat="server" Text="Sample Button" />  
        <asp:Label ID="lblTime" runat="server"></asp:Label>         
        <cc1:MyCustomControl ID="MyCustomControl1" runat="server" />                 
    </ContentTemplate>
</asp:UpdatePanel>

Edit: How you tried to explicitly call the Update method in the button's OnClick event for the Update Panel? This includes the Update panels embedded within the custom control.

Michael Kniskern
btn1 is not the issue - it functions as I would expect doing a "flicker less" post back. It is when the CustomControl event fires that a full posback is occuring.
brendan
Does the custom control need to live within the up1 update panel? Can you move it some where else within the page?
Michael Kniskern
No, it needs to be within the UP. Post backs it fires need to be handled async. In my actual example there is no button, just the custom control in the UP. I put the button in to demonstrate that the UP can handle standard async stuff.
brendan
A: 

Figured out the solution similar issue to this: http://stackoverflow.com/questions/225666/how-can-i-get-an-updatepanel-to-intercept-a-compositecontrols-dropdownlist

Except my control causing the postback was in an updatepanel with a full postback trigger. I was able to pull that control out so it was not nested with in update panels and that resolved it.

brendan