禁用按钮不会提交的UpdatePanel回发 [英] Disabled button doesn't submit postback in UpdatePanel

查看:159
本文介绍了禁用按钮不会提交的UpdatePanel回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的 ASP.NET 页内的UpdatePanel 按钮。这里是我的的UpdatePanel

I have a button inside UpdatePanel on my ASP.NET Page. Here's my UpdatePanel

<asp:UpdatePanel ID="UpdateToolbar" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <table>
            <tr>
                <td>
                    <div id="divPDFBtn">
                        <asp:Button ID="btnPrint" runat="server" OnClick="btnPrint_Click" ToolTip="Click to export report to PDF"
                        Width="100px" Text="Print to PDF" OnClientClick="if(PDFClick()) {return true;} else {alert('2');}" />
                    </div>
                </td>
            </tr>
        </table>
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="btnPrint" />
    </Triggers>
</asp:UpdatePanel>

当我试图关闭按钮的OnClientClick 它不会做回传

When I'm trying to disable button OnClientClick it doesn't do PostBack

下面的例子我的 PDFClick()功能

// Works (does post back and code behind executes))
<script type="text/javascript">
    function PDFClick() {
        document.getElementById("btnPrint").value = "Working...";
        return true;
    };
</script>

// Doesn't work (JS executes, but code behind didn't execute)
<script type="text/javascript">
    function PDFClick() {
        document.getElementById("btnPrint").value = "Working...";
        document.getElementById("btnPrint").disabled = true;
        return true;
    };
</script>

这是我的code后面。我需要做的背一些东西,并打开新的窗口,它的完成之后:

This is my code behind. I need to do some stuff on the back and open new window after it's done:

protected void btnPrint_Click(object sender, EventArgs e)
{
    Response.Write("<script>");
    Response.Write(String.Format("window.open('{0}','_blank')", ResolveUrl("PrintPage.aspx")));
    Response.Write("</script>");
}

请指教我如何可以禁用我的按钮,达到code的后面。

Please advise how I can disable my button and reach code behind.

谢谢!

推荐答案

您可以用异步的setTimeout 禁用按钮:

You can disable the button asynchronously with setTimeout:

<script type="text/javascript">
    function PDFClick(btnPrint) {
        btnPrint.value = "Working...";
        setTimeout(function() { btnPrint.disabled = true; }, 10);
        return true;
    };
</script>

的document.getElementById 呼叫可以从 PDFClick 传递一个参考按钮元素与被删除在这个关键字的OnClientClick

The call to document.getElementById can be removed from PDFClick by passing a reference to the button element with the this keyword in OnClientClick:

OnClientClick="if (PDFClick(this)) { return true; } else { alert('2'); }"

这篇关于禁用按钮不会提交的UpdatePanel回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆