Login or Sign Up to become a member!

EXPERTS, INFORMATION, IDEAS & KNOWLEDGE

Social bookmarker Add this

ASP.NET: Apply a Please Wait message to a Button

From Wiki

Jump to: navigation, search

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:

  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default1.aspx.vb" Inherits="Default1" %>  
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >  
  6. <head runat="server">  
  7.     <title>Untitled Page</title>  
  8. </head>  
  9. <body>  
  10.     <form id="form1" runat="server">  
  11.     <div>  
  12.         <asp:Button ID="Button1" runat="server" Text="Button" />  
  13.     </div>  
  14.     </form>  
  15. </body>  
  16. </html>

Code-Behind:

  1. Partial Class Default15
  2.     Inherits System.Web.UI.Page
  3.  
  4.     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  5.         System.Threading.Thread.Sleep(5000)
  6.         ClientScript.RegisterClientScriptBlock(Me.GetType, _
  7.             "reset", "document.getElementById('" & Button1.ClientID & "').disabled=false;", True)
  8.     End Sub
  9.  
  10.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  11.         Button1.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(Button1, "") _
  12.             & ";this.value='Please wait...';this.disabled = true;")
  13.     End Sub
  14. End Class

This Hack is part of the ASP.NET Hacks collection

435 Rating: 4.0/5 (4 votes cast)