How to make UpdatePanel ignore clicking one button

2020-07-22 03:28发布

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?

2条回答
叼着烟拽天下
2楼-- · 2020-07-22 04:17

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

查看更多
一纸荒年 Trace。
3楼-- · 2020-07-22 04:29

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>
查看更多
登录 后发表回答