简体   繁体   English

ASP.NET:UpdatePanel中的按钮可以引起回发吗?

[英]ASP.NET: can a button in an UpdatePanel cause a postback?

I use UpdatePanels in a ModalPopupExtender and it works well (allowing parts of the dialog box to be refreshed when some controls are clicked, while avoiding full postbacks), but there is one small thing that is not exactly what I would like. 我在ModalPopupExtender中使用UpdatePanels,它运行良好(允许单击某些控件时刷新对话框的一部分,同时避免完整的回发),但是有一件小事情与我的要求不完全相同。

The OK button is disabled by default and enabled when changes are made in the dialog box, so the button is in an UpdatePanel. 默认情况下,“确定”按钮是禁用的,并且在对话框中进行更改时会启用,因此该按钮位于UpdatePanel中。 However, I would like a click on the OK button to cause a full postback. 但是,我想单击“确定”按钮以引起完整的回发。 Is there a "natural" way to achieve that behavior? 是否有一种“自然”的方式来实现这种行为?

NB Avoiding full postbacks is not only a matter of esthetics: they cause the dialog box to disappear from the screen. 注意:避免完全回发不仅是美学问题,它们还会使对话框从屏幕上消失。

If the dialog disappears from the screen, just make it appear again when the full postback completes. 如果对话框从屏幕上消失,则在完整的回发完成后再次显示该对话框。

if(DialogShouldBeVisible)
{
    mpe.Show();
}

Anyways, to cause a full postback you just register it as a regular PostBackTrigger instead of AsyncPostBackTrigger . 无论如何,要引起完整的回发,只需将其注册为常规的PostBackTrigger而不是AsyncPostBackTrigger

<asp:UpdatePanel runat="server">
    <Triggers>
        <PostBackTrigger ControlId="OkBtn">
    </Triggers>
    <ContentTemplate>
       <asp:Button runat="server" id="OkBtn" />
    </ContentTemplate>
</asp:UpdatePanel>

By the way, I recommend against using UpdatePanel and ModalPopupExtender and anything else from the Ajax Control Toolkit. 顺便说一句,我建议不要使用UpdatePanel和ModalPopupExtender以及Ajax Control Toolkit中的其他任何工具。 They don't fit in well with other easily customizable client side stuff. 它们与其他易于自定义的客户端内容不太匹配。 Instead, use dialog from jQuery UI or Bootstrap or some other well supported client side framework, and use AJAX to pass data to the server. 而是使用来自jQuery UIBootstrap或其他一些受支持的客户端框架的对话框 ,并使用AJAX将数据传递给服务器。 It's much easier to put together a nice site that way. 这样,将一个不错的网站放在一起要容易得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM