How to make UpdatePanel ignore clicking one button

2020-07-22 04:12发布

问题:

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:

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>


回答2:

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>.