0

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" />

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.

user2992534
  • 7
  • 1
  • 1
  • 4
  • Normally the button should get it's old value after postback since the page is again submitted to the client. The server didn't even mention that the client has changed it. – Tim Schmelter Dec 18 '13 at 10:38

2 Answers2

4

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));
}
giammin
  • 18,620
  • 8
  • 71
  • 89
1

You forgot to return true.

<asp:Button ID="b_Generate" runat="server" onclick="b_Generate_Click" 
            OnClientClick="this.disabled = true; this.value = 'Please Wait...'; return true;" 
            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"
/>
Patt Mehta
  • 4,110
  • 1
  • 23
  • 47
  • Hey Hii Thanks for your answer but once i add return as true, button doesn't call the b_Generate_Click onclick method. – user2992534 Dec 26 '13 at 19:19