【问题标题】:How to Disable asp.button during loading and enable如何在加载和启用期间禁用 asp.button
【发布时间】:2018-09-06 20:35:07
【问题描述】:

我正在寻找一种在调用方法之前禁用按钮并在方法结束时启用按钮的方法。

代码应该是这样的:

Btn.Enabled = false;
MyMethode();
Btn.Enabled = true;

但 Btn 仍然可以启用。

注意:所有控件都在 UpdatePanel 中。

我已经用 Js 试过了:

ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "document.getElementById('BtnClone').disabled = true; ", true);

ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "document.getElementById('BtnClone').disabled = false; ", true);

按钮保持启用状态。

谢谢

【问题讨论】:

  • 此代码在服务器而不是客户端运行。你需要javascript
  • 好的,我可以直接在C#方法上写Js代码吗?
  • 如果您试图防止双击(dbl-submissions),我认为它已经在某个地方得到了回答。 [?]
  • 防止在方法执行过程中点击。

标签: c# asp.net postback aspbutton


【解决方案1】:

您可以提供的解决方案是,您可以在回帖开始后使用加载 gif 图像,您将以下代码放在母版页中

  <asp:ScriptManager EnablePartialRendering="true" ID="ScriptManagerMain" runat="server"
    AsyncPostBackTimeout="360000">
</asp:ScriptManager>

在母版页的内容占位符之前,放置下面的更新进度

<script type="text/javascript" language="javascript">
            var ModalProgress = '<%= ModalProgress.ClientID %>';         
        </script>
        <script type="text/javascript" src="Scripts/js/jsUpdateProgress.js">
</script>
<asp:Panel ID="panelUpdateProgress" runat="server" CssClass="updateProgress">
            <asp:UpdateProgress ID="UpdateProg1" DisplayAfter="0" runat="server">
                <ProgressTemplate>
                    <div class="divWaiting">
                        <img id="progressImg" src="img/App/Rolling.gif" alt="Processing" height="60px" width="60px" />
                    </div>
                </ProgressTemplate>
            </asp:UpdateProgress>
        </asp:Panel>
        <cc1:ModalPopupExtender ID="ModalProgress" runat="server" TargetControlID="panelUpdateProgress"
            BackgroundCssClass="modalBackground" PopupControlID="panelUpdateProgress" />

Progress Div 中使用的 CSS 如下

.divWaiting
    {
        position: fixed;
        background-color: #313130;
        z-index: 2147483647 !important;
        opacity: 0.8;
        overflow: hidden;
        text-align: center;
        top: 0;
        left: 0;
        height: 100%;
        width: 100%;
        padding-top: 30%;
    }

jsUpdateProgress.js 代码如下,

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginReq);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endReq);

function beginReq(sender, args) {
    // shows the Popup 
    $find(ModalProgress).show();
}

function endReq(sender, args) {
    //  hides the Popup 
    $find(ModalProgress).hide();
}

试试这个,它会在 post back 开始时打开加载 GIF,并在 postback 结束时结束。这将防止双击

【讨论】:

    【解决方案2】:

    我已经用aspx中的这段代码解决了这个问题。

    <ProgressTemplate>
                <div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0; right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity: 0.7;">
                    <span style="border-width: 0px; position: fixed; padding: 50px; background-color: #FFFFFF; font-size: 36px; left: 40%; top: 40%;">Loading ...</span>
                </div>
            </ProgressTemplate>
    

    它会创建一个加载消息,直到更新面板准备好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-19
      • 1970-01-01
      • 2021-01-31
      • 1970-01-01
      • 2017-09-26
      • 2010-10-03
      相关资源
      最近更新 更多