禁用和asp.net回发期间启用按钮 [英] Disabling and enabling a button during postback in asp.net

查看:88
本文介绍了禁用和asp.net回发期间启用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图禁用按钮并更改其文本,而做回发,然后我想改变文本恢复正常时,回发就完成了。

I'm trying to disable a button and change its text while doing a postback and then i want to change the text back to normal when postback is complete.

<asp:Button ID="b_Generate" runat="server" onclick="b_Generate_Click" OnClientClick="this.disabled = true; this.value = 'Please Wait...';" 
Text="Generate PPT"  UseSubmitBehavior="false" 
style="z-index: 1; left: 05px; top: 50px; position: absolute; width: 110px;" 
BorderStyle="Ridge" Font-Bold="True" 
ToolTip="click here" />

通过上面的code我能够禁用按钮,改变后回到启动前的文本,但我不知道如何再次启用该按钮并更改文本回previous 1,一旦回来后完成。

With the above code i'm able to disable the button and change the text before post back starts but i'm not sure how to enable the button once again and change the text back to the previous one once post back is complete.

推荐答案

我通常这个方法添加到我的BasePage重用。您code不处理的验证

I usually add this method to my BasePage for reuse. Your code does not handle validations

/// <summary>
///  Avoid multiple submit
/// </summary>
/// <param name="button">The button.</param>
/// <param name="text">text displayed on button</param>
public void AvoidMultipleSubmit(Button button,string text="wait..." )
{
    Page.ClientScript.RegisterOnSubmitStatement(GetType(), "ServerForm", "if(this.submitted) return false; this.submitted = true;");
    button.Attributes.Add("onclick", string.Format("if(typeof(Page_ClientValidate)=='function' && !Page_ClientValidate()){{return true;}}this.value='{1}';this.disabled=true;{0}",
        ClientScript.GetPostBackEventReference(button, string.Empty),text));
}

这篇关于禁用和asp.net回发期间启用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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