views:

362

answers:

2

Buttons inside UpdatePanels are automatically registered as triggers for that UpdatePanel. Is there a way to make the UpdatePanel ignore one of it's inside buttons? That is, to make it so that clicking this button does NOT trigger any sort of postback?

+1  A: 

That depends on the use for that button. If the button is to call a codebehind method, then a postback is unavoidable as far as I know.

If you'd like your button to only perform a clientside action, then a plain <input type='button'> would do better than a <asp:button>.

Webleeuw
You can prevent a button from posting back by setting the javascript onclientclick event for the button to "return false;" This will stop the postback from the clientside
bechbd
The UpdatePanel isn't forcing the postback... it's the button's standard action. You could use jQuery to interrupt the postback, or like Weebleeuw said, just use a standard input button.If you want to prevent an ajax postback within the UpdatePanel, you can set the Children as Triggers to false and maintain a list of controls that should force an async postback.
orthod0ks
Oh, ChildrenAsTriggers - this is it!!! Thanks orthod0ks!
Aaalf
As a side note, be sure you use UpdateMode="Conditional" on your updatePanels. Failing to do so will cause a full refresh of data in each updatepanel you have on a page (assuming you have more than 1). This results in a lot of unncessary data being passed each time. I'm not sure why they didn't make this the default.
Kyle B.
A: 

You can set UpdateMode='Conditional' then set the which buttons you want to trigger a post-back in the <Triggers> tag. Something like this:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <Triggers>
        <asp:PostBackTrigger ControlID="button1" />
    </Triggers>
    <ContentTemplate>
        ...
        <asp:Button ID="button1" runat="server" Text="Click Me" />
    </ContentTemplate>
</asp:UpdatePanel>
KevnRoberts