Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
ASP.NET: Apply a Please Wait message to a Button
From Wiki
Summary: An example of how we can append a "Please Wait" message to a Button when submitting a form.
Need help with ASP.NET? Come and ask a question in our ASP.NET Forum
Example page with a button:
- <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default1.aspx.vb" Inherits="Default1" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>Untitled Page</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:Button ID="Button1" runat="server" Text="Button" />
- </div>
- </form>
- </body>
- </html>
Code-Behind:
- Partial Class Default15
- Inherits System.Web.UI.Page
- Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
- System.Threading.Thread.Sleep(5000)
- ClientScript.RegisterClientScriptBlock(Me.GetType, _
- "reset", "document.getElementById('" & Button1.ClientID & "').disabled=false;", True)
- End Sub
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- Button1.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(Button1, "") _
- & ";this.value='Please wait...';this.disabled = true;")
- End Sub
- End Class
This Hack is part of the ASP.NET Hacks collection



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.