I try to do two things when I click a button on an ASP.NET page:
- Change the text in ASP: Label.
- Disable button.
I did a lot for this, but I also had difficulties.
For # 1, I thought this should work, but it is not:
<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub BtnSubmit_Click(sender As Object, e As System.EventArgs) Label1.Text = "Working..." System.Threading.Thread.Sleep(5000) Label1.Text = "Done." End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Test Page</title> </head> <body> <form id="form1" runat="server"> <ajaxToolkit:ToolkitScriptManager runat="server" /> <div> <asp:ListBox runat="server" Height="100px" /> <br /> <asp:UpdatePanel runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="BtnSubmit" EventName="Click" /> </Triggers> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Press the button" /> </ContentTemplate> </asp:UpdatePanel> <br /> <asp:Button runat="server" ID="BtnSubmit" OnClick="BtnSubmit_Click" Text="Submit Me!" /> </div> </form> </body> </html>
The message "Work ..." is never displayed.
As for # 2, I added this to the button (I forgot where I found it):
OnClientClick="this.disabled = true; this.value = 'Working...';" UseSubmitBehavior="false"
This had the desired effect of disabling the button and changing its text (value), but it was impossible to change it using the "Text" and "Enabled" properties.
source share