如何在回发触发器中添加进度条

时间:2011-06-23 05:39:02

标签: asp.net

我在项目中使用更新面板。我在面板内使用两个按钮控件。我已经为该按钮提供了回发触发器,但进度条不适用于该按钮控件。因为回发触发器。如果我删除回发触发器它工作正常。但我想将回发触发器添加到我的按钮。任何人都可以帮我解决这个问题。

提前致谢

2 个答案:

答案 0 :(得分:6)

我找到了这个,它对我有用。你可以根据自己的需要改变它 它适用于每个页面回发,如果您想限制然后更改代码以满足您的要求。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.modalPopup
{
background-color: #696969;
filter: alpha(opacity=40);
opacity: 0.7;
xindex:-1;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
//Raised before processing of an asynchronous postback starts and the postback request is sent to the server.
prm.add_beginRequest(BeginRequestHandler);
// Raised after an asynchronous postback is finished and control has been returned to the browser.
prm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
//Shows the modal popup - the update progress
var popup = $find('<%= modalPopup.ClientID %>');
if (popup != null) {
popup.show();
}
}

function EndRequestHandler(sender, args) {
//Hide the modal popup - the update progress
var popup = $find('<%= modalPopup.ClientID %>');
if (popup != null) {
popup.hide();
}
}
</script>
<div>
<asp:UpdateProgress ID="UpdateProgress" runat="server">
<ProgressTemplate>
<asp:Image ID="Image1" ImageUrl="loader.gif" AlternateText="Processing" runat="server" />
</ProgressTemplate>
</asp:UpdateProgress>
<ajaxToolkit:ModalPopupExtender ID="modalPopup" runat="server" TargetControlID="UpdateProgress"
PopupControlID="UpdateProgress" BackgroundCssClass="modalPopup" />
<asp:UpdatePanel ID="pnlData" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click"/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html> 

答案 1 :(得分:5)

<script type="text/javascript">
    var updateProgress = null;

    function postbackButtonClick() {
        updateProgress = $find("<%= UpdateProgress1.ClientID %>");
        window.setTimeout("updateProgress.set_visible(true)", updateProgress.get_displayAfter());
        return true;
    }
</script>

<asp:UpdatePanel runat="server">
        <Triggers>
            <asp:PostBackTrigger ControlID="SyncButton" />
        </Triggers>
        <ContentTemplate>
            <asp:Button runat="server" ID="AsyncButton" Text="Click for Async Postback" OnClick="AsyncButton_OnClick" />
            <asp:Button runat="server" ID="SyncButton" Text="Click for Sync Postback" OnClick="SyncButton_OnClick"
                OnClientClick="return postbackButtonClick();" />
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:UpdateProgress runat="server" ID="UpdateProgress1">
        <ProgressTemplate>
            Please wait...
        </ProgressTemplate>
    </asp:UpdateProgress>